Undefined method 'click' for nil:NilClass (Mechanize)
The code you are using:
member.link_with(text: 'Read biography')
does not find the link, because the link has some space and new lines characters in it. You need to use it like this:
member.link_with(text: /Read biography/)
that code will find the link.
Why is Mechanize returning undefined method 'value=' for nil:NilClass when trying to set a password?
I think your error is coming from
f.field_with(:name => "Login.Password")
which seems to be nil
. For username, I see that you have specified input name LoginCommand.EmailAddress
and for password input name is Login.Password
.
I'd expect anybody who has written this markup to use consistent names. Maybe you should look that the underlying html to see you're using correct field names in your code.
Ruby-Mechanize: undefined method `button_with'
Does it say NoMethodError: undefined method 'button_with' for nil:NilClass
?
It means form
is nil
because form_with(:id => "form-name")
couldn't find your form.
Click javascript tab using mechanize and ruby
I just ran this in my console and you're getting this error
NoMethodError: undefined method `add_field!' for nil:NilClass
because this line returns nil
form = page.form("aspnetForm.add_field!('__EVENTTARGET','')")
Change it to this and it will fix that current error.
form = page.form("aspnetForm")
Clicking link with JavaScript in Mechanize
That's a javascript link. Mechanize will not be able to click it, since it does not evaluate javascript. Sorry!
Try to find out what happens in your browser when you click that link. Does it create a POST or GET request? What are the parameters that are sent to the server. Once you know that, you can emulate the same action in your Mechanize script. Chrome dev tools / Firebug will help out.
If that doesn't work, try switching to a library that supports javascript evaluation. I've used watir-webdriver to great success, but you could also try out phantomjs, casperjs, pjscrape, or other tools
set value for selectlist in Mechanize
Try just:
result_form.scode = 'foo'
set value for selectlist in Mechanize
Try just:
result_form.scode = 'foo'
Related Topics
Fetch VS. [] When Working with Hashes
Difference Between Block and &Block in Ruby
Undefined Method 'Click' for Nil:Nilclass (Mechanize)
Pg::Error: Error: New Encoding (Utf8) Is Incompatible
Extract Text Between Two Tags Using Regex in Ruby
What Is the Path to Learn Bdd on Ruby on Rails
Pass Array Hidden Field in Nested Model Rails
Jruby on Rails VS. Ruby on Rails, What's Difference
If Statement in Ruby Using Regex
How to Install Ruby Gems on MAC
Ruby/Watir/Rasta: Pass the Value from the Excel/Rasta to an Array in Ruby
How to Enable Auto Completion in Ruby's Irb
Ruby Ternary Operator and Method Call
Convert Duration to Hours:Minutes:Seconds (Or Similar) in Rails 3 or Ruby
How to Replace a Pattern in Ruby Array