Greetings fellow Monks,

I've created a small one-page web application and am attempting to use Corion's WWW::Mechanize::Chrome to do some testing. I'm not a web developer, and this is my first attempt at automating anything related to the web.

My problem is that I can't seem to figure out how to click on something (ie. a button) that isn't part of a form. I'm sure I just haven't read through enough of the massive amounts of documentation, but my searching is failing me as well.

I reduced the problem scope to the following:

<!doctype html> <html lang="en"> <head> <title>Testing</title> <script src="https://code.jquery.com/jquery-3.4.1.min.js"></script +> <script> $(document).ready(function() { $("#test-button").click(function() { alert("Tada!"); }); }); </script> </head> <body> <button type="button" id="test-button">Test</button> <input type="file" name="fileupload" value="fileupload" id="fileup +load"> </body> </html>

Both the test-button and the fileupload operations Do The Right Thing in the browser, but fail with mechanize:

use warnings; use strict; use Log::Log4perl qw(:easy); use WWW::Mechanize::Chrome; Log::Log4perl->easy_init($ERROR); my $server = 'http://devvps.ddns.net:3000'; my $url = "$server/test.html"; my $m = WWW::Mechanize::Chrome->new( autoclose => 0, ); $m->get($url); $m->click('test-button');

Here's just a few things I've tried along with the resulting output:

$m->click('test-button'); # No elements found for Button with name 'test\-button' at t/20-mech.t +.pl line 21. $m->click('test-button', 28, 20); # No elements found for Button with name 'test\-button' at t/20-mech.t +.pl line 22. $m->click_button(id => 'test-button'); # No elements found for form number 1 at t/20-mech.t.pl line 23.

Can someone please let me know what I'm missing?

On a side note, it would be nice if I could be informed of a way to click on the fileupload input as well, but that one's not even a button so I'm at a further loss :)

Thanks!

-stevieb

PS: It's a crying shame that Mozilla broke things so that WWW::Mechanize::Firefox no longer works. I don't use Chrome normally.


In reply to WWW::Mechanize::Chrome: Click on button not part of a form by stevieb

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.