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

Friends,

I am using WWW::Mechanize to automate some form entry work. I want to use the <title> of the web pages I visit to ensure the correct pages are being loaded and submitted to. Here's is my code ...
... my $mech = WWW::Mechanize->new(); my $resp = $mech->get( $upLoadUrl ); if ( !$mech->success ) { print "Error could not access $upLoadUrl\n"; exit 1; } my $title = $mech->title(); #print Dumper( $resp ); if ( $title ne $upLoadTitle ) { print "$upLoadUrl is not titled [$upLoadTitle]\n"; exit 1; } $resp = $mech->submit_form ( fields => { j_username => $user, j_password => $password, } ); $title = $mech->title(); # get the new title? print "$upLoadUrl is titled [$upLoadTitle]\n"; print "resp = [ " . Dumper( $resp ) . "]\n"; ...
... and here is the output I get ...
./httpsUpload.pl[224] https://localhost:8080/SecureUpLoad is titled [S +ecure HTTP File Uploader (SHFU) Logon] resp = [ $VAR1 = bless( { '_protocol' => 'HTTP/1.1', '_content' => ' <HTML> <HEAD><TITLE>Props update example jsp</TITLE></HEAD> ...
Why didn't my second callto $mech->title() return Props update example jsp ??? What should I be doing to get this second title?

Plankton: 1% Evil, 99% Hot Gas.

Replies are listed 'Best First'.
Re: Why doesn't $mech->title() change after $mech->submit_form?
by leira (Monk) on Mar 03, 2004 at 23:42 UTC
    Are you sure that your $mech->submit_form succeeded? You can call $mech->success again to be sure.

    Assuming it succeeded, does $mech->content give you the results you were expecting?

    Linda

      I am pretty certain the the $mech->submit_form was successful because when I do my Dumper( $resp ) I can see ...
      resp = [ $VAR1 = bless( { '_protocol' => 'HTTP/11', '_content' => ' <HTML> <HEAD><TITLE>Props update example jsp</TITLE></HEAD>

      Plankton: 1% Evil, 99% Hot Gas.
        Well $mech->title uses HTML::HeadParser on the current value of $mech->content, which is why I think it would be valuable to check whether $mech->content is what you think it is.

        Linda