3

When I run this code:

require 'mechanize'
require 'logger'
require 'nokogiri'
require 'open-uri'

agent = Mechanize.new
agent.log = Logger.new "mech.log"
agent.user_agent_alias = 'Mac Safari'
agent.verify_mode = OpenSSL::SSL::VERIFY_NONE
page = agent.get('https://sarathi.nic.in:8443/nrportal/sarathi/HomePage.jsp')
page = agent.page.links.find{|i| i.text == "Status of Licence"}.click
page.form(:name=>"dlform").field_with(:name=>"dlform:DLNumber").value="TN4020120005045"
page.submit

I get this error:

NoMethodError: undefined method `submit' for #<Mechanize::Page:0x8e644cc>

How can I solve this?

5
  • 1
    You probably want to submit the form, not the page. Commented May 10, 2016 at 9:28
  • just chain the submit with the previous line as page.form(:name=>"dlform").field_with(:name=>"dlform:DLNumber").value="TN4020120005045".submit Commented May 10, 2016 at 11:36
  • @Sam that would invoke "TN4020120‌​005045".submit Commented May 10, 2016 at 12:22
  • @Stefan: My bad, haven't touched mechanize for a while now. Could you then break it into separate calls as form = page.form(:name=>"dlform"); form.field_with(:name=>"dlform:DLNumber").value="TN4020120‌​005045"; form.submit ? Commented May 10, 2016 at 14:45
  • @Sam that looks good, although I don't have Mechanize installed to test it. Maybe you should post that as an answer? Commented May 10, 2016 at 16:32

1 Answer 1

2

@sudhagar, you should submit the form rather than the page. Also break it into separate calls for a cleaner code, as:

...
form = page.form(:name=>"dlform")
form.field_with(:name=>"dlform:DLNumber").value="TN4020120‌​005045"
form.submit 
...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.