Class WWW::Mechanize::Form
In: lib/mechanize/form.rb
Parent: GlobalForm

Synopsis

This class encapsulates a form parsed out of an HTML page. Each type of input fields available in a form can be accessed through this object. See GlobalForm for more methods.

Example

Find a form and print out its fields

 form = page.forms.first # => WWW::Mechanize::Form
 form.fields.each { |f| puts f.name }

Set the input field ‘name’ to "Aaron"

 form['name'] = 'Aaron'
 puts form['name']

Methods

[]   []=   add_field!   field   has_field?   has_key?   has_value?   keys   method_missing   new   set_fields   submit   values  

Attributes

node  [R] 
page  [R] 

Public Class methods

Public Instance methods

Fetch the value of the first input field with the name passed in

Example

Fetch the value set in the input field ‘name‘

 puts form['name']

Set the value of the first input field with the name passed in

Example

Set the value in the input field ‘name’ to "Aaron"

 form['name'] = 'Aaron'

Add a field with field_name and value

Fetch the first field whose name is equal to field_name

Returns whether or not the form contains a field with field_name

has_key?(field_name)

Alias for has_field?

Treat form fields like accessors.

This method sets multiple fields on the form. It takes a list of field name, value pairs. If there is more than one field found with the same name, this method will set the first one found. If you want to set the value of a duplicate field, use a value which is an Array with the second value of the array as the index in to the form. The index is zero based. For example, to set the second field named ‘foo’, you could do the following:

 form.set_fields( :foo => ['bar', 1] )

Submit this form with the button passed in

[Validate]