Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

WWW::Mechanize and input type=image

by dba (Monk)
on Oct 16, 2004 at 14:19 UTC ( #399765=perlquestion: print w/replies, xml ) Need Help??

dba has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

How does one "click" a image? Here is the piece of html:

<input type=image src="/images/btnGoRed.gif"

In this website, they want to click the image to login. Normally it is button type to login.

Replies are listed 'Best First'.
Re: WWW::Mechanize and input type=image
by steves (Curate) on Oct 16, 2004 at 14:27 UTC

    When an image button is clicked, the coordinates of click are sent back as name.x and name.y values, where name is the NAME attribute of the input field. It would seem if you just need to automate form submission, any valid coordinates (e.g., 0,0) would work.

      Thanks Steves. I have 2 follow-up questions.

      1. How do I find out the co-ordinates, as there are many other "image buttons" in the same page.

      Here is the expanded piece of HTML for clarity:
      <tr> <td bgcolor="white"><img height="1" width="1" src="px.gif"></t +d> <td bgcolor="white" colspan="2"><input type="password" name="h +tmPassword" size="10" class="rtnavinput"></td> <td bgcolor="white"><input type=image src="/images/btnGoRed.gi +f" width="15" height="15" border="0"></td> <td bgcolor="white"><img height="1" width="1" src="px.gif"></t +d> </tr>


      2. The syntax for "click" with coordinates is : $mech->click( $button [, $x, $y] ) What should I set $button to? There is no button name in the code.
        I created this HTML:
        <form action="test.cgi" method="GET"> <tr> <td bgcolor="white"><img height="1" width="1" src="px. +gif"></td> <td bgcolor="white" colspan="2"><input type="password" + name="htmPassword" size="10" class="rtnavinput"></td> <td bgcolor="white"><input type=image src="/images/btn +GoRed.gif" width="15" height="15" border="0"></td> <td bgcolor="white"><img height="1" width="1" src="px. +gif"></td> </tr> </form>

        to see what gets sent. It fetches:

        .../test.cgi?htmPassword=&x=8&y=10

        So maybe you need to do something like this:

        $mech->set_fields(x => 1, y => 1); $mech->submit();

        The script probably doesn't attention to the x and y, in which case you could do simply:

        $mech->submit();

        (Untested, and I'd never used WWW::Mechanize.)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2021-09-17 07:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?