I'm trying to get WWW::Mechanize to find a button on a page and click it, but the click_button() function doesn't seem to work properly. For a test example, consider the following website:
<html> <form> <button type="submit" id="test" name="test">My Button</button> </form> </html>
My mechanize script then goes and grabs the webpage:
use WWW::Mechanize; use Data::Dumper; # URL to retrieve $url = 'http://myurl.html '; # Create an instance of Mechanize to scrape my $mechanize= WWW::Mechanize->new( autocheck => 1 ); # Grab the form $mechanize->get($url); $mechanize->form_number('1'); ($output) = $mechanize->current_form(); open(FH, '>dump.txt'); print FH Dumper($output); close(FH); $mechanize->click_button(name => 'test');
Mechanize then gives an error 'no clickable input with name test'. Dumper shows the form was located correctly, but that it contained no items.

However, if I modify that original HTML code snippet to say <input type="submit></input> rather than <button>, Mechanize will successfully run the click_button() routine and Dumper shows that the form contained an HTML::Form::SubmitInput object.

How can I click on buttons then that are of the form <button type="submit"> or even find those buttons on the page? From the dump, it seems like Mechanize ignores them all together. Am I mistaking the functionality of click_button()? Click() may work for a single case, but when there are multiple buttons on a page, I need click_button().

Any help is appreciated.

-- RembrantXVII


In reply to WWW::Mechanize click_button by rembrantxvii

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.