Professional Web Applications Themes

WWW::Mechanize click($button) not finding right button to click - PERL Modules

Based on wise advice from participants of this forum, I rewrote my web automation script using WWW::Mechanize. The script now successfully logs into a secure site over https using a simple username password scheme. I am able to follow links and retrieve various pages. I am now at the point where I need to fill out a form and submit. I have all the necessary field filled out but click($button) keeps saying it can't find the button (there are 8 of them on the page). The value of $button is "View Tabular Data" which is the "alt=" name for a ...

  1. #1

    Default WWW::Mechanize click($button) not finding right button to click

    Based on wise advice from participants of this forum, I rewrote my web
    automation script using WWW::Mechanize. The script now successfully
    logs into a secure site over https using a simple username password
    scheme. I am able to follow links and retrieve various pages. I am
    now at the point where I need to fill out a form and submit.

    I have all the necessary field filled out but click($button) keeps
    saying it can't find the button (there are 8 of them on the page).
    The value of $button is "View Tabular Data" which is the "alt=" name
    for a button img. It is the only button of that name on the page so
    it should find it.

    I should point out that I am using WWW::Mechanize for windows that I
    got from ActiveState. This mod is version 0.72 which does not include
    the submission method of click_button(). I have not been successful
    finding the latest version of this mod for Windows (if you know where
    I can find version 1.02 compiled for Windows, let me know).

    Also, when I was writing the code to automate the secure login, I had
    specified the name of the login button: click("Sign In").
    Originally, that approach didn't work. Since it was the only button
    on the page, I removed the button name: click(). Everything worked
    fine after that. Unfortunately, in the case of this final page, 8
    buttons leaves me choice...I have to pass a button name. I do have
    the option to pass X and Y coordinates but have no idea how those
    coordinates are determined.

    Anyone ever figure out a way around the multi-button problem? Anyone
    else have problems with click($button) not liking button names? Any
    ideas how to get this final piece to work?

    Thanks in advance
    Bart Swordfish Guest

  2. #2

    Default Re: WWW::Mechanize click($button) not finding right button to click

    Bart Swordfish <anotherusercomast.net> writes:
    > Based on wise advice from participants of this forum, I rewrote my web
    > automation script using WWW::Mechanize. The script now successfully
    > logs into a secure site over https using a simple username password
    > scheme. I am able to follow links and retrieve various pages. I am
    > now at the point where I need to fill out a form and submit.
    >
    > I have all the necessary field filled out but click($button) keeps
    > saying it can't find the button (there are 8 of them on the page).
    > The value of $button is "View Tabular Data" which is the "alt=" name
    > for a button img. It is the only button of that name on the page so
    > it should find it.
    The name used must be the name from the "name=" attribute of the
    <input> tag. The alt value is not used.

    Regards,
    Gisle
    Gisle Aas Guest

  3. #3

    Default Re: WWW::Mechanize click($button) not finding right button to click

    On 17 Jun 2004 05:21:43 -0700, Gisle Aas <gisleActiveState.com>
    wrote:
    >The name used must be the name from the "name=" attribute of the
    ><input> tag. The alt value is not used.
    >
    >Regards,
    >Gisle
    What if there is no "name=" attribute? In the case of the button I'm
    trying to push there isn't one.

    <INPUT onclick="return
    CheckRawForm(this.form,'_self','rawdatatable.html' )"
    type=image alt="View Tabular Data"
    src="emsl_files/view_table.gif">

    Is it possible to push a button such as this one? Do I need to use X
    and Y coordinates? If so, how do I determine those coordinates?

    Thanks in advance.
    Bart Swordfish Guest

  4. #4

    Default Re: WWW::Mechanize click($button) not finding right button to click - a little more info

    On 17 Jun 2004 05:21:43 -0700, Gisle Aas <gisleActiveState.com>
    wrote:

    It might help to point out that the button I'm trying to click is the
    second INPUT option in this HTML snippet:

    <TABLE cellSpacing=0 cellPadding=0 width=603 border=0>
    <TBODY>
    <TR>
    <TD width=603 height=5>&nbsp;</TD></TR>
    <TR>
    <TD vAlign=top align=middle><INPUT
    onclick="return
    CheckRawForm(this.form,'_self','rawdatacharts.html ')"
    type=image alt="View Chart"
    src="emsl_files/view_chart.gif">&nbsp;&nbsp;<INPUT
    onclick="return
    CheckRawForm(this.form,'_self','rawdatatable.html' )"
    type=image alt="View Tabular Data"
    src="emsl_files/view_table.gif">&nbsp;&nbsp;<INPUT
    onclick="return
    CheckRawForm(this.form,'_self','rawdataxml.html')"
    type=image alt="Download XML Data"
    src="emsl_files/download_xml.gif">&nbsp;&nbsp;<INPUT
    onclick="return
    CheckRawForm(this.form,'_self','rawdatacsv.html')"
    type=image alt="Download CSV Data"
    src="emsl_files/download_csv.gif">&nbsp;&nbsp;<INPUT
    onclick="return
    CheckRawForm(this.form,'_self','rawdatacsvmatrix.h tml')"
    type=image alt="Download CSV Matrix"

    src="emsl_files/download_csvmatrix.gif"></TD></TR></TBODY></TABLE>

    Looks like I can't call it by name as there is no name attribute (as I
    learned from the previous response...thanks). I tried to trick it and
    insert a button with a name: <BUTTON TYPE="button" NAME="DoIt"
    onclick="return
    CheckRawForm(this.form,'_self','rawdatatable.html' )"</BUTTON></TD> but
    that didn't work either. It still said it couldn't find an input type
    named DoIt (...damn it). I did check to make sure the insertion
    worked. The button was there it just wasn't found when click("DoIt")
    was called. This gets back to my problem with the Sign In button.
    That didn't like being called by name either. Once I removed the name
    it worked fine. Of course, that was the only button on the page.

    Any ideas? Thanks.
    >Bart Swordfish <anotherusercomast.net> writes:
    >
    >> Based on wise advice from participants of this forum, I rewrote my web
    >> automation script using WWW::Mechanize. The script now successfully
    >> logs into a secure site over https using a simple username password
    >> scheme. I am able to follow links and retrieve various pages. I am
    >> now at the point where I need to fill out a form and submit.
    >>
    >> I have all the necessary field filled out but click($button) keeps
    >> saying it can't find the button (there are 8 of them on the page).
    >> The value of $button is "View Tabular Data" which is the "alt=" name
    >> for a button img. It is the only button of that name on the page so
    >> it should find it.
    >
    >The name used must be the name from the "name=" attribute of the
    ><input> tag. The alt value is not used.
    >
    >Regards,
    >Gisle
    Bart Swordfish Guest

  5. #5

    Default Re: WWW::Mechanize click($button) not finding right button to click

    Bart Swordfish <anotherusercomcast.net> writes:
    > On 17 Jun 2004 05:21:43 -0700, Gisle Aas <gisleActiveState.com>
    > wrote:
    >
    > >The name used must be the name from the "name=" attribute of the
    > ><input> tag. The alt value is not used.
    > >
    > >Regards,
    > >Gisle
    >
    > What if there is no "name=" attribute? In the case of the button I'm
    > trying to push there isn't one.
    >
    > <INPUT onclick="return
    > CheckRawForm(this.form,'_self','rawdatatable.html' )"
    > type=image alt="View Tabular Data"
    > src="emsl_files/view_table.gif">
    >
    > Is it possible to push a button such as this one?
    You will have to use the find_input() method on the HTML::Form object
    to locate the image and then click on it. Something like this (untested):

    my $f = $mech->form_number(1); # select first form
    my $image = $f->find_input(undef, "image", 4); # select 4th image in form
    $image->click($f, 1, 1); # click on it

    It appears that HTML::Form is not compatible with common browsers in
    this case as it will not send back the coordinates for nameless
    images. Not really sure if it matter for your application. The
    attached patch (on top of libwww-perl-5.800) fixes this problem.

    Index: lib/HTML/Form.pm
    --- lib/HTML/Form.pm 16 Jun 2004 10:06:07 -0000 1.44
    +++ lib/HTML/Form.pm 18 Jun 2004 07:13:20 -0000 1.46
    -1160,11 +1161,11 sub form_name_value
    my $self = shift;
    my $clicked = $self->{clicked};
    return unless $clicked;
    - my $name = $self->{name};
    - return unless defined $name;
    return if $self->{disabled};
    - return ("$name.x" => $clicked->[0],
    - "$name.y" => $clicked->[1]
    + my $name = $self->{name};
    + $name = (defined($name) && length($name)) ? "$name." : "";
    + return ("${name}x" => $clicked->[0],
    + "${name}y" => $clicked->[1]
    );
    }


    --
    Gisle Aas
    Gisle Aas Guest

  6. #6

    Default Re: WWW::Mechanize click($button) not finding right button to click - a little more info

    Bart Swordfish <someonecomcast.net> writes:
    > On 17 Jun 2004 05:21:43 -0700, Gisle Aas <gisleActiveState.com>
    > wrote:
    >
    > It might help to point out that the button I'm trying to click is the
    > second INPUT option in this HTML snippet:
    >
    > <TABLE cellSpacing=0 cellPadding=0 width=603 border=0>
    > <TBODY>
    > <TR>
    > <TD width=603 height=5>&nbsp;</TD></TR>
    > <TR>
    > <TD vAlign=top align=middle><INPUT
    > onclick="return
    > CheckRawForm(this.form,'_self','rawdatacharts.html ')"
    > type=image alt="View Chart"
    > src="emsl_files/view_chart.gif">&nbsp;&nbsp;<INPUT
    > onclick="return
    > CheckRawForm(this.form,'_self','rawdatatable.html' )"
    > type=image alt="View Tabular Data"
    > src="emsl_files/view_table.gif">&nbsp;&nbsp;<INPUT
    > onclick="return
    > CheckRawForm(this.form,'_self','rawdataxml.html')"
    > type=image alt="Download XML Data"
    > src="emsl_files/download_xml.gif">&nbsp;&nbsp;<INPUT
    > onclick="return
    > CheckRawForm(this.form,'_self','rawdatacsv.html')"
    > type=image alt="Download CSV Data"
    > src="emsl_files/download_csv.gif">&nbsp;&nbsp;<INPUT
    > onclick="return
    > CheckRawForm(this.form,'_self','rawdatacsvmatrix.h tml')"
    > type=image alt="Download CSV Matrix"
    >
    > src="emsl_files/download_csvmatrix.gif"></TD></TR></TBODY></TABLE>
    >
    > Looks like I can't call it by name as there is no name attribute (as I
    > learned from the previous response...thanks). I tried to trick it and
    > insert a button with a name: <BUTTON TYPE="button" NAME="DoIt"
    > onclick="return
    > CheckRawForm(this.form,'_self','rawdatatable.html' )"</BUTTON></TD> but
    > that didn't work either. It still said it couldn't find an input type
    > named DoIt (...damn it).
    HTML::Form will always ignore any inputs of type button as it does not
    know anything about JavaScript. It looks like you have to figure out
    what the CheckRawForm() function does and emulate that to get any
    further here.

    --
    Gisle Aas
    Gisle Aas Guest

Similar Threads

  1. set button.click from .as file
    By skermajo_1 in forum Macromedia Flex General Discussion
    Replies: 2
    Last Post: October 25th, 11:20 PM
  2. Replies: 2
    Last Post: May 28th, 06:23 AM
  3. button won't stay down after click
    By joejoe2288 in forum Macromedia Flash Sitedesign
    Replies: 1
    Last Post: April 5th, 02:22 AM
  4. double click button(mc)
    By stwingy webforumsuser@macromedia.com in forum Macromedia Flash Actionscript
    Replies: 3
    Last Post: January 20th, 07:07 AM
  5. Replies: 2
    Last Post: October 14th, 11:06 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139