stevieb has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: WWW::Mechanize::Chrome: Click on button not part of a form
by Corion (Patriarch) on Dec 01, 2019 at 16:00 UTC | |
by stevieb (Canon) on Dec 01, 2019 at 16:06 UTC | |
|
Re: WWW::Mechanize::Chrome: Click on button not part of a form
by karlgoethebier (Abbot) on Dec 01, 2019 at 16:06 UTC | |
by stevieb (Canon) on Dec 01, 2019 at 16:10 UTC | |
by karlgoethebier (Abbot) on Dec 01, 2019 at 16:43 UTC | |
|
Re: WWW::Mechanize::Chrome: Click on button not part of a form
by 1nickt (Canon) on Dec 01, 2019 at 14:49 UTC | |
by stevieb (Canon) on Dec 01, 2019 at 15:07 UTC |