field method for Win32::IE::Mechanize

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View


I'm trying to execute the following (still incomplete) script:

use strict;

use Win32::IE::Mechanize;

my $ie = Win32::IE::Mechanize->new(visible=>1);

$ie->get("something was here but is removed for security reasons");
sleep 1;
my $webpagetext = "nothing yet";
$webpagetext = $ie->content(format=>"text");
my @webforms = $ie->forms;
my $webformstotal = @webforms;
print "number of forms found = $webformstotal\n";
print "webform : $webforms[0]\n";
my $loginform = $ie->current_form;
print "loginform : $loginform\n";

$loginform->field("user",'some user was here');
$loginform->field("password",'some password was here');

but I'm getting the error code :

"Can't locate object method "field" via package "Win32::IE::Form" at"

Does anyone have any idea what this beginner is doing (stupidly)

Thanks in advance,



Re: field method for Win32::IE::Mechanize


> sleep 1;

Nothing to do with your question, but the sleep is not needed. IE::Mecahnize
waits until all requests are completed anyway (at least that is my

> my $webpagetext = "nothing yet";

Again, not relevant to the question, but this can be rewritten as:
my $webpagetext;
No need to assign anything, or faster yet:
my $webpagetext = $ie->content(format=>"text");

> my $loginform = $ie->current_form;
> print "loginform : $loginform\n";
> $loginform->field("user",'some user was here');

current_form is a "status" method. It returns the current form, but I don't
think it actually does anything with it. I have only limited experience with
IE::Mech, but I think what is going wrong is that you are not telling the
script which form on the page to use, or not correctly anyway. Instead I
think you should use: form_name (or if the form doesn't have a name:

What has always worked for me is:

(some code omitted)
my $ie = Win32::IE::Mechanize->new( visible => 1);
$ie->form_name("some name here");
$ie->field("some field", 'some value');

Also you probably don't need all the extra variables if all you are doing is
trying to fill out a simple login form.  You can get rid of $loginform,
@webforms and $webformstotal

Try that and see if it helps you out any....


Site Timeline