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

Tried to execute the following commands, recorded with HTTP::Recorder:

$agent->form_number(1);
$agent->field('password', 'xxx');
$agent->field('login_name', 'xxx');
$agent->click('login');

That doesn't work, however. I traced the requests made by the browser and the script with Wireshark, and based on that I made the following modification:

$agent->field( login => 'Submit+Query' );
$agent->click('login');

That works, but why?

Replies are listed 'Best First'.
Re: Click button with WWW::Mechanize
by choroba (Cardinal) on Mar 11, 2016 at 14:56 UTC
    Is there any JavaScript code in the page? Can you show the source of the login button?
    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

      Here it is - no javascript:

      <form action="./xxx.cgi?login" method="post">
       <h1>Login</h1>
       <input  type="text"     name="login_name">
       <input  type="password" name="password">
       <input  type="submit" name="login">
       <button type="submit" name="login">Login</button>
      </form>
      

        I haven't looked at Mechanize's source, but I'm guessing that it doesn't look at <button> elements when parsing the page for forms.

        -Thomas
        "Excuse me for butting in, but I'm interrupt-driven..."