Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Cannot re-enter username, password into login form

by GlassKnees (Initiate)
on Aug 01, 2014 at 15:07 UTC ( [id://1095924]=perlquestion: print w/replies, xml ) Need Help??

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

I'm trying to write a perl script that will log into a particular site. There is a bug on the site that issues a bogus error (browser does not accept cookies), and username & passwords are cleared. But if I manually re-enter the username and password, my logi is successful.

I'm trying to emulate this behavior in perl by testing for the cookies error after my initial login attempt, I repeat the following:
$mech->set_fields(Username => $username, Password => $password); $mech->submit(); $output_page = $mech->content();
The resulting behavior is the site responds as if I did not repopulate the username and password fields and simply clicked on the Login button.

During debugging, I discovered that if I invoke the click() method prior to initially populating the username and password fields, they don't get filled in by the set_fields() method.

How can I repopulate fields on the same webpage after invoking the click or submit methods?

Replies are listed 'Best First'.
Re: Cannot re-enter username, password into login form
by Anonymous Monk on Aug 01, 2014 at 22:48 UTC

    How can I repopulate fields on the same webpage after invoking the click or submit methods? <?i>

    As documented?

    What module are you using? What website are you visiting?

      I'm using WWW::Mechanize

      Here is a snippet of code:
      $mech->get($url); $mech->form_name('loginform'); $mech->set_fields(user_login => $username, user_pass => $password); $mech->click(); my $output_page = $mech->content(); if ($output_page =~ m/cookies/) { $TestStatus = 1; ok( $TestStatus , "Login failed - Browser not enabled to accept co +okies error"); # Try logging in again - should work this time... $mech->get($url); $mech->form_name('loginform'); $mech->set_fields(user_login => $username, user_pass => $password); $mech->click(); }

      The first attempt fails and I get the cookies error, which tells me that I'm populating the user_login and user_pass fields. But after invoking the click method, I can't seem to repopulate the fields - at least that's how the site is behaving...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1095924]
Approved by toolic
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-04-24 20:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found