Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8709571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:23:38+00:00 2026-06-13T04:23:38+00:00

I ran into a problem when using Mechanize to submit a login form. For

  • 0

I ran into a problem when using Mechanize to submit a login form. For example, if I need to log into bitbucket:

a = Mechanize.new
a.get('https://bitbucket.org/') do |page|
  login_page = a.click(page.link_with(text: 'Log In'))

  my_page = login_page.form_with(action: '/account/signin/') do |f|
    # The "username" and "password" below are the values of the "name" attribute of the two login form fields
    f.username = 'MY_ACCOUNT_NAME' 
    f.password = 'MY_PASSWORD' 
  end.click_button
end

That’s pretty straight forward, however, not all login forms have the same “name” value on those two fields. WordPress’ login form, for example, uses “log” and “pwd” . This would invalidate the above code.

I want to pass some parameters into this method so that it can be used on different login forms.
I attempted to follow “How to convert from a string to object attribute name?” but was unsuccessful:

# auth_info is a hash
def website_login(auth_info) 
  a = Mechanize.new
  a.get(auth_info[:login_page_url]) do |page|
    land_page = page.form_with(action: auth_info[:login_form_action]) do |f|
      # Now I am stuck with these two lines
      ????????
      ????????
      # I tried to do it like this. Not working.
      f.instance_variable_set('@'+auth_info[:username_field_name], auth_info[:username])
      f.instance_variable_set('@'+auth_info[:password_field_name], auth_info[:password])
    end.click_button
  end
end

Really appreciate if someone can help out.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T04:23:39+00:00Added an answer on June 13, 2026 at 4:23 am

    Resolved. It’s like this:

    f.send(auth_info[:username_field_name] + '=', auth_info[:username])
    f.send(auth_info[:password_field_name] + '=', auth_info[:password])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am building a form using a js+html and I ran into a problem.
I ran into a problem using Springsource Tool Suite when writing some groovy scripts
while working on a school project i ran into a problem using javascript to
<XmlInfo /> I ran into problem using Perl's popular SOAP::Lite module, where it wouldn't
I ran into a problem using java objects in jython today because jython is
I ran into a strange problem using a C# webservice client to call a
Alright, I have ran into a problem when using DownloadDataAsync and having it return
I ran into a problem using case classes and parameterized types with an upper
I was thinking about this when I ran into a problem using std::ofstream. My
I ran into a problem that occurs when using the module PanedWindow Tix. Let's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.