themirror
themirror

Reputation: 10287

Mechanize: Search all Forms

It appears that both of these give me access to the first FORM element in a document:

page.form
page.forms.first

How can I search for a particular checkbox like

page.form.checkbox_with(:name=>"yep")

if I don't know which FORM it is inside?

Upvotes: 1

Views: 541

Answers (1)

Dogbert
Dogbert

Reputation: 222080

Do you want all the forms with that checkbox, or only the first one?

For the first one, do

form = page.forms.detect { |f| f.checkbox_with(:name => "yep" ) }

For all, do

forms = page.forms.select { |f| f.checkbox_with(:name => "yep" ) }

Upvotes: 3

Related Questions