[Mechanize-users] Converting Watir script to Mechanize

Luis Lebron
Tue, 15 Jan 2008 16:14:24 -0000

I have a Watir script that I would like to convert to a Mechanize
script. The watir code looks like this

require ''watir''
include Watir

def test
  ie = IE.new
  ie.goto(''http://cpref.gsm.com/inter.asp?r=8084'')

  ie.text_field(:name,
''inter_string'').set(''Potassium'')
  ie.button(:id, ''image1'').click
  ie.link(:text, /Potassium/).click
  ie.image(:src,
''http://cpref.gsm.com/images/plus_yellow.gif'').click

  ie.text_field(:name,
''inter_string'').set(''Xopenex'')
  ie.button(:id, ''image1'').click
  ie.link(:text, /Xopenex/).click
  ie.image(:src,
''http://cpref.gsm.com/images/plus_yellow.gif'').click

  ie.text_field(:name,
''inter_string'').set(''Lasix'')
  ie.button(:id, ''image1'').click
  ie.link(:text, /Lasix/).click

  ie.link(:url,
''javascript:document.selectForm.submit()'').click
end


I started working on the Mechanize script but it is throw the following error:
c:/ruby/lib/ruby/gems/1.8/gems/mechanize-0.6.11/lib/mechanize/form.rb:302:in
`method_missing'': undefined method `inter_string='' for
#<WWW::Mechanize::Form:0x33653c8> (NoMethodError)

Here the script I''m testing

require ''mechanize''
agent = WWW::Mechanize.new
page = agent.get(''http://cpref.gsm.com/inter.asp?r=8084'')
search_form = page.forms.with.name("interdrugs").first
search_form.inter_string = "Potassium"
search_form.submit
puts page.body

Any help would be greatly appreciated.

Luis