Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Mechanizing Javascript form

by perrin (Chancellor)
on Nov 10, 2003 at 18:27 UTC ( [id://305929]=note: print w/replies, xml ) Need Help??


in reply to Mechanizing Javascript form

Most JavaScript hardly does anything at all as far as the server is concerned, and the server is the only thing that matters here. Just look at the script, figure out what it does (change a form value? submit another form?) and then write Perl code that does the same thing. In many cases, the JavaScript can be ignored completely.

Replies are listed 'Best First'.
Re:* Mechanizing Javascript form
by Roy Johnson (Monsignor) on Nov 10, 2003 at 19:20 UTC
    In this case, the Javascript is the whole purpose of the page. Or it seems to be. I haven't fully deciphered it, but the form itself has no action attribute. It takes username and password and (somehow) authenticates the intranet user for the session.

    I have to get my session authenticated so I can check that protected documents are being served. It promises to be tedious, but that's not Perl's fault.

      Forms can exist and function without an action attribute.

      Show us the page, why don't you, and let us figure out what it's doing?

      The fundamental point is that a JavaScript form almost certainly doesn't do anything that an equivalent HTML form can do. The JS probably just checks that certain fields aren't empty or something like that -- checks the buttons/fields before submitting. After submitting, it's just another form.



      ($_='kkvvttuubbooppuuiiffssqqffssmmiibbddllffss') =~y~b-v~a-z~s; print
        More directly Perl-related is the issue I'm wrestling with right now. I'm trying to get to the page with the form, by finding the Login link on a startup page.

        Here's the pertinent code. On an earlier pass, I had the commented section uncommented, so that I got a local copy of the file.

        my $result = $a->get($start_page); #open PAGE, ">top.html" or die "Could not open top.html:$!\n"; #print PAGE $result->as_string; #close PAGE; #die "PAGE written\n"; my $link = $a->find_link(text => 'Login') or die "Found no Login link\n";
        The file contained this line, which is what I expected the find_link to return, but it did not find it.
        <a href="PORTAL30.wwsec_app_priv.login?p_requested_url=http://yadda.ya +dda.yadda..."><font size=-1 class="BannerSecondaryText">Login</a>

        I'm tempted to say it's a bug in Mechanize, but I'm not having a good brain day, so maybe I'm just misunderstanding how find_link is supposed to work.

        Update: it looks like the reason for this is broken HTML: an unclosed link earlier on the page.

        The JS does appear to be essentially validation. At the risk of drifting away from Perl, I'll include the JS section and the form def. I appreciate the help.

        The JavaScript...

        <script language="JavaScript" type="text/JavaScript"> <!-- var smtry=0; function MM_reloadPage(init) { //reloads the window if Nav4 resized if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseI +nt(appVersion)==4)) { document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize= +MM_reloadPage; }} else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH +) location.reload(); } MM_reloadPage(true); function resetCredFields() { document.Login.PASSWORD.value = ""; } function submitForm() { // Strip target without params targetWithParams = document.Login.target.value; queryStrIdx = targetWithParams.indexOf("?"); if ( queryStrIdx > 0 ) { // there is query string if( targetWithParams.indexOf("SMLOCALE") <= 0 ) // SMLOCALE hs + been defined document.Login.target.value = targetWithParams ; } else { document.Login.target.value = document.Login.target.value ; alert("Final Target is " + document.Login.target.value ); } // document.Login.submit(); } function isempid (c) { submitForm(); if((c >= "100000") && (c <= "999999")){ alert("You have to Enter your Network UserID and password t +o login"); return false; } return true; } //--> </script> <script language="JavaScript1.2" type="text/javascript"> function windowHeight() { if(document.all){ //IE availW = document.body.clientHeight; } else{ //Netscape availW = window.innerHeight; } return availW; } </script>
        ...and the form...
        <form NAME="Login" METHOD="POST" onSubmit="javascript:return i +sempid(this.USER.value);"> <INPUT TYPE=HIDDEN NAME="SMENC" VALUE="ISO-8859-1"> <INPUT type=HIDDEN name="SMLOCALE" value="US-EN"> <tr> <td align="center"> <table width="400" border="0" cellspacing="0" ce +llpadding="1"> <tr> <td align="center">&nbsp;</td> </tr> <tr> <td bgcolor="#000000"><table width="100%" bo +rder="0" cellspacing="0" cellpadding="0"> <tr bgcolor="#FFFFFF"> <td colspan="2"><table width="100%" bo +rder="0" cellspacing="0" cellpadding="3"> <tr align="center" bgcolor="#CCCCC +C"> <td colspan="2"> <script language="JavaScript" type="text/JavaScrip +t"> if (smtry) document.write ('<B><font color=red>Invalid Us +erid or Password.<br></font></b>'); </script> <b>Please enter your Network Username and Password</b></td> </tr> <tr bgcolor="#CCCCCC"> <td align="right"><b>Username</b +></td> <td align="center"> <input name= +"USER" type="text" id="USER" size="30" maxlength="80"> </td> </tr> <tr bgcolor="#CCCCCC"> <td colspan="2"><img src="images +/spacer.gif" width="1" height="1"></td> </tr> <tr bgcolor="#CCCCCC"> <td align="right"><strong>Passwo +rd</strong></td> <td align="center"><input name=" +password" type="password" id="password" size="30" maxlength="80"></td +> </tr> <tr bgcolor="#CCCCCC"> <td height="10" colspan="2"><img + src="images/spacer.gif" width="1" height="1"></td> </tr> <tr valign="middle" bgcolor="#CCCC +CC"> <input type=hidden name=target value="http://my.un +ocal.com/pls/portal30_sso/portal30_sso.wwsso_app_admin.ls_login?site2 +pstoretoken=v1.1~1363~5F3F82C6798011021FC6FD5452764DC556F2283462F74ED +DA8157273011910A6F35FCE49D515765277DEFF3C14C90177B648B52D8F9739C33FE1 +5B1437ECF6351966AEB84D56B4FFCD0F1D7BC0265D3F7385A881AE52CE9700EE4F31E +D216152DC9142A3C9018529A11AE3E1913AE47D4A18C4EF638FB059B3C1480FFAD397 +CCFAA2C36B17AD50809F904033D583E7B137B80CA6102C2F224235805C6756859E26E +BF2A84888FCF95F7EBFAA0402E37E161A4A4A2F7CFC52E9F9FC58B0CEB389896221EF +3EF144558792E96083B3714B48590A7F1B0C12AD7669AAD49223BE90B97B61C3BC933 +7F341C9288960C5E4FB9FE8D3AD5D929E84"> <input type=hidden name=smauthreason value="0 +"> <input type=hidden name=smtryno value=""> <td height="45" colspan="2" alig +n="center"><input type="submit" name="Submit" value="Login"></td> </tr> </table></td> </tr> </table></td> </tr> </table> </td> </tr> </form>

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://305929]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-04-19 05:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found