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...