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

Hello , I'm trying to log in into the web configuration panel of a device and create backup. The module I'm using is WWW::Scripter .It says  No such field 'userName' at /home/angel/perl5/lib/perl5/WWW/Mechanize.pm line 750. I'm using my router's web panel for the test . Here is my code so far :
use WWW::Scripter; my $agent = new WWW::Scripter; my $username = 'username'; my $pass= 'password'; $agent->use_plugin('JavaScript'); $agent->get('http://192.168.0.1/'); $agent->cookie_jar(HTTP::Cookies->new); $agent->form_name("loginForm"); $agent->field('userName' => $username); $agent->field('pcPassword' => $pass); $agent->click();

Replies are listed 'Best First'.
Re: Automating backup with WWW::Scripter
by bliako (Abbot) on Apr 16, 2019 at 09:14 UTC

    hit the page manually with a browser, view source, search for the form and verify that the field names you are using match the form's.

      I've already checked that . Here is sample of the HTML
      <ul> <li id="unLi" class="unLi"><input class="text" id="userName" type="tex +t" maxlength="15" /></li> <li class="blank"></li> <li id="pwLi" class="pwLi"><input class="text" id="pcPassword" type="p +assword" maxlength="15"/></li> </ul>
      I think that the parameters are passed to JavaScript function and I'm not passing them properly because the script pass them to the html form and I'm not sure if it passes them to the function as well
      unction CheckUserPswInvalid() { var userName = $("userName"); var pcPassword = $("pcPassword"); if(!CheckUserPswChars(userName.value)) { userName.select(); userName.focus(); return false; } if(!CheckUserPswChars(pcPassword.value)) { pcPassword.select(); pcPassword.focus(); return false; } return true; }

        Before you proceed it's worth also checking the form name.

        Maybe all you want is to POST a form and get a cookie back?

        I can't help with WWW::Scripter. But here is an idea about debugging: save html and all javascript dependencies locally, modify with alert() and point Scripter to these files to verify that the javascript plugin at least works.

Re: Automating backup with WWW::Scripter
by choroba (Cardinal) on Apr 16, 2019 at 11:57 UTC
    Crossposted to StackOverflow. It's considered polite to inform about crossposting to prevent unnecessary work of hackers not attending both the sites.

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
      I will announce it from now on . Excuse me !