Class WWW::Mechanize::Form
In: lib/www/mechanize/form.rb
lib/www/mechanize/form/image_button.rb
lib/www/mechanize/form/file_upload.rb
lib/www/mechanize/form/field.rb
lib/www/mechanize/form/multi_select_list.rb
lib/www/mechanize/form/radio_button.rb
lib/www/mechanize/form/option.rb
lib/www/mechanize/form/button.rb
lib/www/mechanize/form/select_list.rb
lib/www/mechanize/form/check_box.rb
lib/www/mechanize/monkey_patch.rb
Parent: Object

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

Classes and Modules

Class WWW::Mechanize::Form::Button
Class WWW::Mechanize::Form::CheckBox
Class WWW::Mechanize::Form::Field
Class WWW::Mechanize::Form::FileUpload
Class WWW::Mechanize::Form::ImageButton
Class WWW::Mechanize::Form::MultiSelectList
Class WWW::Mechanize::Form::Option
Class WWW::Mechanize::Form::RadioButton
Class WWW::Mechanize::Form::SelectList

External Aliases

fields -> elements
pretty_inspect -> inspect

Attributes

action  [RW] 
buttons  [R] 
checkboxes  [R] 
enctype  [RW] 
fields  [R] 
file_uploads  [R] 
form_node  [R] 
method  [RW] 
name  [RW] 
page  [R] 
radiobuttons  [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'

This method adds a button to the query. If the form needs to be submitted with multiple buttons, pass each button to this method.

Add a field with field_name and value

This method builds an array of arrays that represent the query parameters to be used with this form. The return value can then be used to create a query string for this form.

Submit form using button. Defaults to the first button.

Removes all fields with name 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 calculates the request data to be sent back to the server for this form, depending on if this is a regular post, get, or a multi-part post,

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 a Hash with the key 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 => { 1 => 'bar' } )

Submit this form with the button passed in

[Validate]