in reply to WWW::Mechanize::Chrome: Click on button not part of a form
The method ->click only works with elements contained within <form> elements, unless you directly hand it elements to click on.
The easiest way is likely to get the element you want, and then hand it to the click method (or, as shown below, do it all in one call):
use warnings; use strict; use Log::Log4perl qw(:easy); use WWW::Mechanize::Chrome; Log::Log4perl->easy_init($ERROR); my $html = <<'HTML'; <!doctype html> <html lang="en"> <head> <title>Testing</title> </head> <body> <button type="button" id="test-button" onclick="alert('Ta-daa')">T +est</button> <input type="file" name="fileupload" value="fileupload" id="fileup +load"> </body> </html> HTML my $m = WWW::Mechanize::Chrome->new( autoclose => 0, ); $m->update_html($html); my $button = $m->selector('#test-button', single => 1); print "Clicking on button with content:" . $button->get_attribute('inn +erHTML'); print "\n"; $m->sleep(1); $m->click({ dom => $button }); # Or, all in one go $m->sleep(1); $m->click({ selector => '#test-button' }); $m->sleep(10);
I have removed the external reference to jquery and other stuff that needed external files.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: WWW::Mechanize::Chrome: Click on button not part of a form
by stevieb (Canon) on Dec 01, 2019 at 16:06 UTC |