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":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.