From: barjunk Date: 2006-08-06T06:05:04+09:00 Subject: Re: Mechanize Aaron Patterson wrote: > On Sat, Aug 05, 2006 at 04:20:09PM +0900, barjunk wrote: [snip] > > > s = form.field("add_release[release_focus_name]") > > The variable "s" is a SelectList class which represents a "select" html > tag. > > > > s.value = s.options[5].value > > A SelectList class has many Options associated with it. An Option > represents an "option" tag. Here Gregory is picking one of the options > and setting it as the value for this select list. > > > > > > > t = form.field("add_release[hide_from_frontpage]") > > > t.value = t.options[0].value > > > > what do add_release[release_focus_name] and the add_release etc...stand > > for? > > "add_release[release_focus_name]" is the name of the select field. > Gregory is probably dealing HTML that looks something like this: > > > > If you wanted to look at the text for each option, your code might look > something like this (using the variables Gregory had): > > s.options.each { |o| puts "Text: '#{o.text}' Value: '#{o.value}'" } > > Make sure to check out the RDoc for WWW::Mechanize::SelectList and > WWW::Mechanize::Option at http://mechanize.rubyforge.org/ Aaron, this helps tremendously! It would be awesome if these kind of examples were in the api docs mentioned above. As it stands, the example : selectlist.value = selectlist.options.first.value gives no context whatsoever and being new to both ruby and web programming, I'm at a bit of a disadvantage. Maybe a hint about how to go through the API to get the answer for myself? :) One additional question I have is, what if there is more than one form on the page? Mechanize is awesome stuff, and I have already leveraged it to some degree. Thanks for the additional help. Mike B.