javascriptperlmechanizewww-mechanize-firefox

Perl Fill Out Form Based on Element ID


I am trying to use WWW::Mechanize to fill out a form. Unfortunately my page requires JS so I am now using WWW::Mechanize::Firefox.

Here is the element I am trying to fill out.

<input id="ember745" class="ssTextboxField"></input>

The set_field() function takes an element name. How would I give it an element ID (ember 745) and have it fill the form in?

Here is my code so far

use WWW::Mechanize::Firefox;
my $mech = WWW::Mechanize::Firefox->new(autoclose => 0);
$mech->get(URL);

$mech->form_number(1);
$mech->submit_form(
fields => {
    ember745 => $value
});

Solution

  • Figured it out, had to use a selector

    my $field = $mech->selector('input.ssTextboxField', single => 1);
    $mech->field( $field => $value );