Perl Tutorials
Using WWW-Mechanize
Perl Basics

Using WWW-Mechanize

Manipulating Forms

Selecting a Form

WWW::Mechanize makes the automation of form submission just a few statements. Access the forms() function for a list of all forms on the page. Forms can be selected for later use with the manipulation functions later by number on page, name, ID, and with specified fields.


$m->forms;
$m->form_number(INT);
$m->form_name('name');
$m->form_id('id');
$m->form_with_fields(@list);

Setting Fields

The field and select methods are used to set form fields. The form field requires two fields, one that contains the name of the field, and a second that contains a value. A third value used to select the field when there are multiple fields with the same name is optional.


$m->field('field', 'value', [number]);
$m->select('field', 'value');

The select statement is used to select values in a select field. To select multiple values in a multi select box use an array for the value field.


$m->select('field', $value);
$m->select('field', @values);

Multiple fields can be set in one statement with the set_fields function.


$m->set_fields(field1 => 'value', field2 => 'value');

Introduction and Getting Started <<  1 2 3  >> Submitting Forms and Example Scripts
New Content