Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Clicking on a button without a form using Win32::IE::Mechanize

by venkatesan_G02 (Sexton)
on Sep 21, 2009 at 10:11 UTC ( #796511=perlquestion: print w/replies, xml ) Need Help??
venkatesan_G02 has asked for the wisdom of the Perl Monks concerning the following question:

Hi All,


I am trying to automate an interaction with the web page and i am using Win32::IE::Mechanize module as the page involves javascripting. I am able to login to the page and access all the information i need but the problem arises when i try to log off from the page. The button is not associated to any form tag.


Below is the HTML code of the page i am trying to access.
<form action="#" name="colorset"><input type="hidden" id="clr" + name="c" value=""></form> <fieldset class="buttonbartop"> <input class="titlebutton" type="button" name="searchcases" value="S +earch All Cases" onclick="javascript:searchcases();"> <input class="titlebutton" type="button" name="getnew" value="Get N +ew Case" onclick="javascript:searchcase();"> <input class="titlebutton" type="button" name="create" value="Creat +e Case" onclick="javascript:makecase();"> <input class="titlebutton" type="button" name="addressbook" value=" +Address Book" onclick="javascript:addressbook();"> <input class="newfeaturebtn" type="button" name="userhistory" value +="My History" onclick="javascript:showhistory();"> <input class="newfeaturebtn" type="button" name="usersettings" valu +e="Settings" onclick="javascript:showsettings();"> <input class="titlebutton" type="button" name="reportproblem" value +="Report a Problem" onclick="javascript:reportproblem();"> <input class="titlebutton" type="button" name="logoff" value="Log O +ff" onclick="javascript:snag('?logoff');"> </fieldset>



My Perl code is given below:
#!C:/perl/bin/perl.exe use Win32::IE::Mechanize; my $url = 'http://mallet'; my $ie = Win32::IE::Mechanize->new(visible => 1); $ie->get($url); sleep(2); #wait for 2 sec so that the requested page will be displayed +. $ie->click_button(value => 'Log Off');



Though the above code is not returning any error, it's not loggin off. I know i can try WWW::Selenium module but i have written most part of my code using Win32::IE::Mechanize module and i think there might be a way to accomplish this.


Any suggestions would be greatly appreciated!!!


Thanks

Replies are listed 'Best First'.
Re: Clicking on a button without a form using Win32::IE::Mechanize
by marto (Bishop) on Sep 21, 2009 at 10:31 UTC

    No use strict; no use warnings; is poor practice. Aside from this does IE show that there are any errors with the JavaScript that is running? Can you alter the function do display an 'alert' to see if it has been clicked?

    Try $ie->click_button( name => 'logoff' ); in case the space character is causing an issue, this is just a guess.

    Martin

      Hi,


      IE does not show any error. I tried using the name parameter but it's not working. I even tried other buttons in the fieldset class but of no use.

        Are other buttons or links with onclick="javascript:xxx('yyy');" working? I mean, not from this fieldset, but from the same page ...

        I suspect that javascript is not working.

Re: Clicking on a button without a form using Win32::IE::Mechanize
by Anonymous Monk on Sep 21, 2009 at 15:08 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://796511]
Approved by marto
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2018-01-17 00:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How did you see in the new year?










    Results (194 votes). Check out past polls.

    Notices?