in reply to Re^7: How do I click Javascript button with Win32::IE::Mechanize
in thread How do I click Javascript button with Win32::IE::Mechanize

I checked your script(which you gave as example) it's working, But still having some problem in my script.Please check
#!/usr/bin/perl use strict; use warnings; use Win32::IE::Mechanize; my $ie = Win32::IE::Mechanize->new( visible => 1 ); my $url ='http://url/go'; $ie->get( $url ); $ie->follow_link (text =>"subForm('UA_Signin','signOff')")|| die"can't + find text $!"; # $ie->find_link (url=>"javascript:subForm('UA_Signin','signOff')");
I checked it with other options
#$ie->find_link (number=>2); # $ie->find_image(image =>"ua/images/button-signoff.gif")|| die"can't + find image$!"; # $ie->find_image(alt =>" ")|| die"can't find image$!";
One thing i want to let you know while hitting on signoff button (or reference) manually ,page moves to login page but the url (at address bar)does not get changed. Hope it will help you to find out my solution. Thanks

Replies are listed 'Best First'.
Re^9: How do I click Javascript button with Win32::IE::Mechanize
by rshrivaQ (Initiate) on Dec 21, 2007 at 12:56 UTC
    Did you get what i am trying to make you understand? Thanks
      rshrivaQ,

      As I am sure you have noticed, you get notified when someone replies to your post. Since you replied to yourself here, I did not get informed. I have been busy with my day job so have no had a chance to get back to you, however it is considered polite to wait until someone replies in their own time.

      You did not provide us with the JavaScript code in question. Please note the dummy JavaScript function I have written into the HTML you provided:
      <HTML> <HEAD> <TITLE>Cygent: Error</TITLE> <SCRIPT> function subForm(){ alert('Hello!'); } </SCRIPT> <SCRIPT LANGUAGE="JavaScript" SRC="ua/script/rollover.js"></SCRIPT> <SCRIPT SRC="common/script/js_common.js" language="javascript"></SCRIP +T> </HEAD> <BODY leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" BG +COLOR=#999999 LINK=#"0033CC" vlink="#0033CC" TEXT=#000000 onload="on +Load()"> <FORM NAME="mainForm" METHOD="POST" ACTION="/go" target="_top" onsubmi +t="return false;"> <INPUT TYPE=hidden NAME=from VALUE="UA_Error"> <INPUT TYPE=hidden NAME=to VALUE=""> <INPUT TYPE=hidden NAME=task VALUE=""> <!-- BEGIN Outer shell - sets minimum width for screen. Use 1004 for 1 +024 pixel screens and 780 for 800 pixel screens --> <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH="100%" BGCOLOR="#FFF +FFF"> <!-- END title bars --> <TR> <TD ALIGN=LEFT VALIGN=TOP CLASS="FormBodyBGColor" COLSPAN="2"> <TABLE BORDER=0 CELLPADDING=10 CELLSPACING=0 WIDTH="100%"><TR><T +D ALIGN=LEFT VALIGN=TOP> <TABLE BORDER=0 CELLPADDING=10 CELLSPACING=0 WIDTH=620> <TR> <TD VALIGN=TOP> <FONT FACE="Arial" size="2">The following error has occurred:</f +ont> </TD> </TR> <TR> <TD VALIGN=TOP COLSPAN=2> <FONT FACE="Arial" size="2"> The system has encountered an error while processing your requ +est. <BR>Please click the &quot;sign off&quot; button provided below +, sign back into the system, and try your request again. </FONT> </TD> </TR> <TR> <TD COLSPAN=2> <FONT FACE="Arial" size="2"> Please click 'Go Back' button to return to the previous screen +, and continue from there. If you continue to encounter problems, ple +ase use the 'Sign Off' button to exit the application. </FONT> </TD> </TR> <TR> <TD> <A HREF="javascript:history.back()"> <IMG BORDER="0" SRC="ua/images/button_back.gif"></A></TD> <TD VALIGN=BOTTOM ALIGN=RIGHT><A HREF="javascript:subForm('UA_Sig +nin','signOff')"><IMG BORDER="0" SRC="ua/images/button-signoff.gif" a +lt=""></A></TD> </TR> </TABLE> </TD></TR></TABLE> </TD> </TR> </TABLE> <!-- END Outer shell --> </FORM> </BODY> </HTML>
      Now, when I run this code, I see the alert window as expected. Unless the JavaScript function subForm exists in the JavaScript file you include, nothing will happen when the link is followed, as there is no function in the HTML you have provided.

      #!/usr/bin/perl use strict; use warnings; use Win32::IE::Mechanize; my $ie = Win32::IE::Mechanize->new( visible => 1 ); my $url ='file:///c:/test.html'; $ie->get($url); $ie->follow_link(url => "javascript:subForm('UA_Signin','signOff')");
      Feel free to add the required error checking.

      Hope this helps

      Martin
        Thanks for encouraging me.I am copying the different code with java script function
        <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META http-equiv=Content-Type content="text/html; charset=windows-1252 +"> <META content="MSHTML 6.00.2900.3243" name=GENERATOR></HEAD> <BODY><PRE>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitiona +l//EN"&gt; &lt;HTML&gt; &lt;HEAD&gt; &lt;META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset +=iso-8859-1"&gt; &lt;TITLE&gt;Consulting Plus - Single Sign-On&lt;/TITLE&gt; &lt;link rel="stylesheet" href="../style/MenuBar.css"&gt; &lt;script language="JavaScript" type="text/script"&gt; function doSubmit() { document.ctlogonform.method="post"; document.ctlogonform.action="cp_logon_ct.html"; document.ctlogonform.submit(); } &lt;/script&gt; &lt;/HEAD&gt; &lt;BODY bgcolor="#999999" class="linkColor" vlink="FFFFFF"&gt; &lt;table width="1004" border="0" cellspacing="0" cellpadding= +"0"&gt; &lt;tr&gt; &lt;td bgcolor="#FFFFFF" width="4"&gt;&amp;nbsp;&lt;/td&gt +; &lt;td rowspan="2" bgcolor="#FFFFFF" width="222"&gt;&lt;im +g src="../images/qwest_blu_wht1.gif" alt=""&gt;&lt;/td&gt; &lt;td width="381" bgcolor="#FFFFFF"&gt;&amp;nbsp;&lt;/td& +gt; &lt;td colspan="2" bgcolor="#FFFFFF"&gt; &lt;div align="right"&gt; &lt;/div&gt; &lt;/td&gt; &lt;td width="4" class="qwestBlueBGColor" height="16"&gt;& +amp;nbsp;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td bgcolor="#FFFFFF" width="4"&gt;&amp;nbsp;&lt;/td&gt +; &lt;td colspan="3" bgcolor="#FFFFFF" height="77"&gt; &lt;font color="006699" size="2"&gt;&lt;b&gt;Consulting Pl +us - Single Sign-On&lt;/b&gt;&lt;/font&gt; &lt;/td&gt; &lt;td width="4" class="qwestBlueBGColor"&gt;&amp;nbsp;&lt +;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td width="4" class="qwestBlueBGColor"&gt;&amp;nbsp;&lt +;/td&gt; &lt;td width="222" class="qwestBlueBGColor"&gt;&amp;nbsp;& +lt;/td&gt; &lt;td width="381" class="qwestBlueBGColor"&gt;&amp;nbsp;& +lt;/td&gt; &lt;td width="222" class="qwestBlueBGColor"&gt;&amp;nbsp;& +lt;/td&gt; &lt;td width="184" class="qwestBlueBGColor"&gt;&amp;nbsp;& +lt;/td&gt; &lt;td width="4" class="qwestBlueBGColor"&gt;&amp;nbsp;&lt +;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td width="4" class="formBodyBGColor" height="21"&gt;&a +mp;nbsp;&lt;/td&gt; &lt;td width="222" class="pagename" height="21"&gt;SIGN O +N&lt;/td&gt; &lt;td colspan="3" class="message" height="21" &gt;&amp;n +bsp;&amp;nbsp;To access Consulting Plus, Please enter your CUID and P +assword then click the SIGN ON button.&lt;/td&gt; &lt;td width="4" class="qwestBlueBGColor" height="21"&gt;& +amp;nbsp;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td width="4" class="formBodyBGColor"&gt;&amp;nbsp;&lt;/td& +gt; &lt;td colspan="4" class="formBodyBGColor"&gt; &lt;FORM name="ctlogonform" ACTION="cp_logon_ct.html" METHOD=P +OST ACCEPT-CHARSET="UTF-8"&gt; &lt;INPUT TYPE="hidden" NAME="auth_mode" VALUE="basic"&gt; &lt;table border=0 cellpadding=10 cellspacing=0 width="100 +%"&gt; &lt;tr&gt; &lt;td valign=top&gt; &lt;table border=0 cellpadding=0 cellspacing=0 wid +th="100%"&gt; &lt;tr&gt; &lt;td width="50%"&gt;&lt;img src="../imag +es/spacer.gif" alt="" width=1 height=1 border=0&gt;&lt;/td&gt; &lt;td width="50%"&gt;&lt;img src="../imag +es/spacer.gif" alt="" width=1 height=1 border=0&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td valign=top&gt;&lt;FONT COLOR="#FF00 +00" FACE="Arial" SIZE="2"&gt;&lt;/FONT&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td colspan="2"&gt;&lt;img src="../i +mages/spacer.gif" alt="" width=1 height=10 border=0&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td valign=top&gt; &lt;font face="Arial" size=2&gt;&lt;b&gt;C +UID:&lt;/b&gt;&lt;/font&gt; &lt;br&gt; &lt;input type="text" name="user" value="" + maxlength="26" size="22" &gt; &lt;/td&gt; &lt;td valign=top&gt; &lt;font face="Arial" size=2&gt;&lt +;b&gt;Password:&lt;/b&gt;&lt;/font&gt; &lt;br&gt; &lt;INPUT TYPE="password" NAME="p +assword" VALUE="" SIZE="22" MAXLENGTH="20"&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/FORM&gt; &lt;/td&gt; &lt;td width="4" class="qwestBlueBGColor"&gt;&amp;nbsp;&lt;/td +&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td colspan="6" class="qwestBlueBGColor" height="16"&gt +; &lt;table border="0" cellpadding="0" width="100%" bgcolor= +"#000000"&gt; &lt;tr&gt; &lt;td valign=TOP width="2%"&gt;&lt;/td&gt; &lt;td valign=TOP width="32%"&gt;&amp;nbsp;&lt;/td +&gt; &lt;td align=CENTER valign=TOP width="32%"&gt; &lt;div align="CENTER" &gt;&lt;a class="navBar +Bottom2" href="javascript:document.forms[0].reset();" &gt;RESET&lt;/a +&gt;&lt;/div&gt; &lt;td&gt; &lt;td align=RIGHT valign=TOP width="32%"&gt; &lt;div align="RIGHT"&gt;&lt;a href="javascrip +t:document.forms[0].submit();" class="navBarBottom2"&gt;SIGN ON&lt;/a +&gt;&lt;/div&gt; &lt;/td&gt; &lt;td valign=TOP width="2%"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td colspan="6" class="qwestBlueBGColor"&gt; &lt;div align="right"&gt;&lt;img src="../images/qwest_ +cygent_basea.gif" alt="" width="1000" height="3"&gt;&lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td width="4" bgcolor="ffffff" height="24"&gt;&amp;nbsp +;&lt;/td&gt; &lt;td colspan="3" bgcolor="ffffff" height="24"&gt; &lt;/td&gt; &lt;td colspan="2" bgcolor="ffffff" height="24"&gt; &lt;div align="right"&gt;&lt;img src="../images/qwest_ +RSA_gray.gif" alt="" width="187" height="39"&gt;&lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td colspan="6" bgcolor="#3E6679"&gt; &lt;div align="right"&gt;&lt;img src="../images/qwest_ +cygent_baseb_gray.gif" alt="" width="1000" height="3"&gt;&lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/BODY&gt; &lt;/HTML&gt; </PRE></BODY></HTML>
        and my script is
        #!/usr/bin/perl #use strict; #use warnings; use Win32::IE::Mechanize; my $ie = Win32::IE::Mechanize->new( visible => 1); my $url ='http://test.html'; #dummy url $ie->get( $url ); $ie->set_visible($username,$password ); # $ie->follow_link("javascript:document.forms[0].submit();"); $ie->find_link(url => "javascript:document.forms[0].submit();")|| die + "can't call $!";
        script is able to load the page and passing the inputs but its not hitting the SIGN ON button. Thanks