Samy_rio has asked for the wisdom of the Perl Monks concerning the following question:
Hi monks, I have tried to automate the browsing method using WWW::Mechanize module as below:
use strict; use Data::Dumper; use WWW::Mechanize; use POSIX qw(strftime); my $currSysDate =strftime ("%b".'&year='."%y", localtime); # DAY Langu +age my $mech = WWW::Mechanize->new(autocheck => 1); my $url = "http://www.somenet.com/login.aspx"; my $user = 'user'; my $pass = 'pass'; $mech->get( $url ); if ($mech->success()) { $mech->submit_form( form_name => 'Form1', fields => { txtUsername => $user, txtPassword => $pass, }, button => 'Button3', ); $mech->get("http://www.somenet.com/showCardEmpMonthlyReport.aspx? +month=$currSysDate&Reptype=&empcode=$user"); my $str = $mech->content(); print $str; }
I am getting error as:
Error GETing javascript:__doPostBack('EmpSideMenu1$lnkAttendance',''): + Protocol scheme 'javascript' is not supported at array.pl line 10047
Source of particular URL is:
<TD class="sidemenu" style="BACKGROUND-IMAGE: url(Images1\MenuBg.jpg); + BACKGROUND-REPEAT: repeat-x"> <a id="EmpSideMenu1_lnkAttendance" href="javascript:__doPostBack('EmpS +ideMenu1$lnkAttendance','')" style="color:White;width:160px;">Attenda +nce Report</a></TD> <script language="javascript"> <!-- function __doPostBack(eventTarget, eventArgument) { var theform; if (window.navigator.appName.toLowerCase().indexOf("netscape") + > -1) { theform = document.forms["Form1"]; } else { theform = document.Form1; } theform.__EVENTTARGET.value = eventTarget.split("$").join(":") +; theform.__EVENTARGUMENT.value = eventArgument; theform.submit(); } // --> </script>
From chatterbox, I came to know WWW::Mechanize doesn't support Javascript. Based on Corion suggestion I have used Win32::IE::Mechanize module. Eventhen javascript hyper-link is not working in follow_link.
use strict; use Data::Dumper; use Win32::IE::Mechanize; my $ie = Win32::IE::Mechanize->new( visible => 1 ); my $url = "http://www.somenet.com/login.aspx"; my $user = 'user'; my $pass = 'pass'; $ie->get( $url ); if ($ie->success()) { $ie->submit_form( form_name => 'Form1', fields => { txtUsername => $user, txtPassword => $pass, }, button => 'Button3', ); $ie->follow_link( text_regex => qr/Attendance Report/i ); #Not wo +rking $ie->submit_form( form_name => 'Form1', button => 'Button1', ); print $ie->content(); } __END__ Some time Error as: Can't locate object method "warn" via package "sssself" (perhaps you f +orgot to load "sssself"?) at C:/Perl/site/lib/Win32/IE/Mechanize.pm l +ine 971.
How to follow up the javascript hyper-link? Please help me. Thanks in advance.
Updated I have updated sssself->warn( "No inputcontrol by the name '$fname'" ); as $self->warn( "No inputcontrol by the name '$fname'" ); in Win32::IE::Mechanize. Still not working.
Regards,
Velusamy R.
eval"print uc\"\\c$_\""for split'','j)@,/6%@0%2,`e@3!-9v2)/@|6%,53!-9@2~j';
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Follow-up Javascript Hyperlink
by perrin (Chancellor) on Nov 04, 2006 at 17:27 UTC | |
Re: Follow-up Javascript Hyperlink
by Anonymous Monk on Jul 13, 2007 at 04:26 UTC | |
by jiperez (Initiate) on Feb 14, 2012 at 14:08 UTC | |
by enemyofthestate (Monk) on Jan 08, 2014 at 23:18 UTC |
Back to
Seekers of Perl Wisdom