From: tim.bounceback@... Date: 2007-04-03T08:50:04+09:00 Subject: Re: Simple problem w/ WWW::Mechanize On Apr 2, 7:25 pm, Aaron Patterson wrote: > Hi Tim, > > > > On Tue, Apr 03, 2007 at 08:00:15AM +0900, tim.bounceb...@gmail.com wrote: > > Hi all, I'm fairly new to Ruby, and, as an exercise, I'm writing some > > code for webforms. However, I can't seem to get the following code to > > work - instead, I get the following error: > > wikitesting.rb:8:in `get': undefined method `myform' for > > # (NoMethodError) > > from wikitesting.rb:10 > > > Probably pretty simple, and I can see it's something wrong with the > > way I called the function, however, I've spent some time on it and > > can't figure it out. Here's the code: > > require 'rubygems' > > require 'mechanize' > > def get(pagename) > > agent = WWW::Mechanize.new > > agent.user_agent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT > > 5.1)' > > page = agent.get('http://en.wikipedia.org/w/index.php?title='+ > > pagename + '&action=edit') > > myform = page.form('editform') > > Try replacing this line: > > > return page.myform.fields.form('wpTextbox1') > > With this: > > return myform.wpTextbox1 > > You've already found the form and stored it in the 'myform' variable. > > > end > > text = get('Computer') > > pp text > > Also, if you have more questions, be sure to join the mechanize mailing > list: > > http://rubyforge.org/mailman/listinfo/mechanize-users > > -- > Aaron Pattersonhttp://tenderlovemaking.com/ Thanks for replying. I still get a similar error, though: wikitesting.rb:8:in `get': undefined method `wpTextbox1' for nil:NilClass (NoMethodError) from wikitesting.rb:10 Any ideas? By the way, I've joined the mailing list, and any future questions I might have will probably be directed there. Thanks, Tim