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
Aaron Patterson
2008-Jan-15 21:39 UTC
[Mechanize-users] Converting Watir script to Mechanize
Hi Luis, On Tue, Jan 15, 2008 at 10:14:24AM -0600, Luis Lebron wrote:> 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.The problem is most likely a bug in hpricot. Hpricot has problems parsing forms in tables, so those methods may not get added to the form object. If you know that that form field is supposed to be on the form object, just treat the form object like a hash, and it will add the field if its missing. For example: search_form[''inter_string''] = "Potassium" Hope that helps. -- Aaron Patterson http://tenderlovemaking.com/