I have been working on a Ruby Script that enters in data into a search field and then needs to click on the enter button. By looking at the “pp” my data is correctly inputing into the search field. The problem I am having is clicking on the “enter” button. What is happening is that it is not moving forward it is just refreshing the current screen. When I manually access the website in question via IE, enter the search data and hit enter on my keyboard it doesn’t roll to the search screen; I have to click with the mouse on enter to get it to move forward. If I use Chrome and preform the same task with the keyboard enter then it opens a new tab. How do I get this programmatically to move forward?
Here is my code:
require 'rubygems'
require 'mechanize'
agent = Mechanize.new
agent.verify_mode = OpenSSL::SSL::VERIFY_NONE
page = agent.get('https://somewebsite.com')
check_form = page.form
check_form['ct100$MainContent$txtNumber'] = 'J520518'
pp page
page = agent.submit(check_form, check_form.buttons.first)
pp page
page.links.each do |link|
puts link.text
end
Here is snippit from the output:
...
<forms
#<Mechanize::Form
<name nil>
<method "POST">
<action "">
<fields
...
[field:0xb627a0 type: name:ct100$MainContent$txtNumber value: J520518]>
...
<buttons
[submit:0xb6d8ac type: submit name: ct100$MainContent$btnEnter value: Enter]
}>}>
...
<forms
#<Mechanize::Form
<name nil>
<method "POST">
<action "">
<fields
...
[field:0xb627a0 type: name:ct100$MainContent$txtNumber value: ]>
...
<buttons
[submit:0xb6d8ac type: submit name: ct100$MainContent$btnEnter value: Enter]
As always, thank you so much for all your help!
Ok I was able to parse using watir since I am using IE. Then I was able to use nokogiri to parse the last page. Ultimately, I was on the right track with the code above, but Mechanize is not able to handle JavaScript at this time. Since watir is a driver for the brower rather than acting like it’s own browser it is able to handle the JavaScript. I hope this helps anyone that lands on this question.