Reputation: 1060
Im working on submitting the search form for yellowpages.com, but when I do pretty print page I notice in the name field it is blank. How would I tell mechanize to locate that form if the name field is blank?
require 'mechanize'
agent = Mechanize.new
page = agent.get('http://www.yellowpages.com')
pp page
Output:
#<Mechanize::Form
{name nil}
{method "GET"}
{action "/search"}
{fields
[text:0x3fd6990db510 type: text name: search_terms value: ]
[text:0x3fd6990db36c type: text name: geo_location_terms value: Dallas, TX]
[hidden:0x3fd6990db13c type: hidden name: tracks value: true]}
{radiobuttons}
{checkboxes}
{file_uploads}
{buttons [button:0x3fd6990df87c type: submit name: value: Search]}>}>
Upvotes: 2
Views: 85
Reputation: 54984
You can go by the number it appears:
page.forms[0]
In fact, since it's the first one (and like lots of other "first" things) you can just do:
page.form
Upvotes: 0
Reputation: 368954
The form has an action
attribute; specify that information:
page.form_with(:action => '/search') do |form|
...
end
Upvotes: 1