Hi guys, I am very new to Perl and i am learning on the fly while i try to automate some projects for work. So far its has been a lot of fun.

I am working on generating a report for a customer. I can get this report from a web page i can access.
First i will need to fill a form with my user name, password and choose a server from a drop down list, and log in.
Second i need to click a link for the report section.
Third a need to fill a form to create the report.

I found that its hard for me to debug what i do since i cant see the webpage i currently hold in $mech and verify i am on the right place.
Second, i am not sure i read the source code correctly to find the field names etc.

Here is what i wrote so far:

my $mech = WWW::Mechanize->new(); my $url = 'http://xxx; $mech->get( $url ); $mech->submit_form( form_number => 1, fields => { Username => 'someone', Password => 'pass', Server => 'Live' }, ); die unless ($mech->success);

The source code is:

<!-- login panel begin --> <div id="ctl00_ctl00_cphserver_cphLogin_pnlLogin" class="leftpanel" st +yle="Visibility:visible;Display:block;"> <span style="display:inline-block;width:120px;">Username</span> <br \> <input name="ctl00$ctl00$cphserver$cphLogin$txtUser" type="text" id="c +tl00_ctl00_cphserver_cphLogin_txtUser" onKeyPress="javascript: return + txtUser_onKeyPress();" style="color:Navy;width:140px;" /> <br \> <span style="display:inline-block;width:120px;">Password</span> <br \> <input name="ctl00$ctl00$cphserver$cphLogin$txtPW" type="password" id= +"ctl00_ctl00_cphserver_cphLogin_txtPW" onKeyPress="javascript: return + txtPW_onKeyPress();" style="color:Navy;width:140px;" /> <br \> <span style="display:inline-block;width:120px;">Server</span> <br \> <select name="ctl00$ctl00$cphserver$cphLogin$ddlServers" id="ctl00_ctl +00_cphserver_cphLogin_ddlServers" style="color:Navy;width:140px;"> <option value="Live">Live</option> <option selected="selected" value="Test">Test</option> </select> <br \> <br \> <input type="submit" name="ctl00$ctl00$cphserver$cphLogin$btnSignIn" v +alue="Sign-In" id="ctl00_ctl00_cphserver_cphLogin_btnSignIn" /> <br /> <br /> </div> <!-- login panel end -->

Please help me the understand how to debug easily and how to read the source code so i can program correctly.

Thank you! Yaniv


In reply to using and debuging www Mechanize by yantar

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.