schnarff has asked for the wisdom of the Perl Monks concerning the following question:

I've got sort of a weird situation on my hands here. I'm trying to use WWW::Mechanize to log into a page where the username/password fields are not initially present on the page (they appear via JavaScript once I click a certain radio button). Doing
my $mech = WWW::Mechanize->new(); $mech->get('http://www.forex.com/login.html'); $mech->field('txtLogin', 'myuserid');
gets me the error "No such field 'txtLogin' at /usr/share/perl5/WWW/Mechanize.pm line 1033". Meanwhile, I see from WWW::Mechanize::FAQ that there's zero support for JavaScript within Mechanize.

That said, is there a way to force Mechanize to pass parameter/value pairs to a form when no such parameters exist in the downloaded form? Alternately, is there any other workaround that might be applicable here? The page in the code snippet above is the real deal, so feel free to look at it for other fixes.

Thanks,
Alex Kirk

Replies are listed 'Best First'.
Re: WWW::Mechanize for nonexistent fields?
by friedo (Prior) on Dec 23, 2005 at 17:56 UTC
    In situations like this, you generally have to disect the form and javascript to figure out what parameters need to be submitted. Rather than attempting to access the page and fill out the form, just have your script do a POST request to the form's action, providing the proper credentials to log in.
Re: WWW::Mechanize for nonexistent fields?
by planetscape (Chancellor) on Dec 23, 2005 at 23:02 UTC
Re: WWW::Mechanize for nonexistent fields?
by jbrugger (Parson) on Dec 23, 2005 at 19:48 UTC
    Indeed, friedo is right.
    The formfields are generated by javascript, thus www::mechanize cannot handle them. (as you noted as well)
    The only application (i know of) that can be used to test javascript from within a browser is watir, written in Ruby.
    But anyone with a bit knowledge of Perl should find out that Ruby isn't that hard, and looks a lot like Perl (flamewar follows :) )

    "We all agree on the necessity of compromise. We just can't agree on when it's necessary to compromise." - Larry Wall.
      I hadn't user watir, but for me samie has done the work nicely (testing).