Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
I have logged into my adsl modem using the following code.

use strict; use WWW::Mechanize; use LWP::Simple; use MIME::Base64; my $pubIP = get("http://whatismyip.org/"); my $url = "http://$pubIP/resetrouter.html"; my $username = "foo"; my $password = "bar"; my $button = "Save/Reboot"; my @args = ( Authorization => "Basic " . MIME::Base64::encode( $username . ':' . $password ) ); my $mech = WWW::Mechanize->new(autocheck => 1); $mech->credentials( $url, "test", $username, $password ); $mech->get( $url, @args ) or die $mech->die; print $mech->content; $mech->click($button);

the return value of print $mech->content; is as follows which means i have successfully logged into my adsl modem:

<html> <head> <meta HTTP-EQUIV='Pragma' CONTENT='no-cache'> <link rel="stylesheet" href='stylemain.css' type='text/css'> <link rel="stylesheet" href='colors.css' type='text/css'> <script language="javascript"> <!-- hide function btnReset() { var code = 'location="rebootinfo.cgi"'; eval(code); } function frmLoad() { var sysReboot = '0'; var lanRefresh = '0'; if ( sysReboot == '1' ) btnReset(); else if ( lanRefresh == '1' ) { var code = 'location="resetrouter.cgi?lanRefresh=0"'; eval(code); } } // done hiding --> </script> </head> <body onLoad='frmLoad()'> <blockquote> <center> <br> <strong>Click the button below to save and reboot the rout +er.</strong> </blockquote></center> <p align="center"> <input type='button' onClick='btnReset()' value='Save/Reboot' +> <br> </p> </body> </html>

but immediately after print statement, as i pass through the $mech->click($button) statement i am getting the error Can't call method "click" on an undefined value at c:/Perl/site/lib/WWW/Mechanize.pm line 707.

did lot of googling and searching perl monk as well...got the results as saying the object is not initiated...in my case $mech....but i can't see how.

Please suggest me where am i doing it wrong.


In reply to Can't call method "click" on an undefined value by neoanantha

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2021-10-27 00:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (91 votes). Check out past polls.

    Notices?