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

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

Replies are listed 'Best First'.
Re^12: How do I click Javascript button with Win32::IE::Mechanize
by marto (Cardinal) on Dec 27, 2007 at 13:50 UTC
    I have told you a couple of times to note the differences between the $ie->find_link() method, which for some reason you insist on using, and the $ie->follow_link() method. In your previous examples where you failed to show us any of the JavaScript clicking an image ran a JavaScript function. Now for some reason this seems to have changed and you just want to submit a form? Regardless...

    First off, please read and understand the Win32::IE::Mechanize documentation, I appreciate that this may not be easy if English is not your native language.

    Once again you are using $ie->find_link(); which does not click a link, it returns an object describing the link.

    If you read the Win32::IE::Mechanize documentation you will see that there is an entire section of form methods, and examples for populating fields and submitting forms using the $ie->submit_form() method. I suggest you go read up on how to use this to populate these fields, and submit the form. There is an example in the synopsis showing exactly how to do this.

    Update: typo s/not to note/to note/

    Hope this helps

    Martin