in reply to WWW::Mechanize::Firefox clicking on a div doesn't work
The last line you tried should work if you wrap it inside of a hash -- assuming there is an event that is triggered by clicking the div you've selected. The WWW::Mechanize::Firefox documentation mentions that you have to use the hash along with the 'dom' key. The example below adds a custom event to ensure that there is an event tied to clicking of the div:
use strict; use warnings; use diagnostics; use feature 'say'; use WWW::Mechanize::Firefox; my $mech = WWW::Mechanize::Firefox->new( autodie => 1 ); # Load up google search $mech->autoclose_tab(0); $mech->get('http://google.ca'); say "Google retrieved" if $mech->success(); # Make sure the bottom line turns red if we successfully click the <di +v> my $str = " var tmp = document.getElementById('prm-pt'); tmp.onclick = function() { this.style.backgroundColor = 'red'; }; "; $mech->eval_in_page( $str ); say "Event set" if $mech->success(); # Type something in the search box $mech->form_id( 'tsf' ); $mech->set_fields( q => 'time' ); # Click the div, the bottom line should turn red my @divs = $mech->xpath('//div[@id="prm-pt"]'); $mech->click( { dom => $divs[0], synchronize => 0 } ); say "<div> clicked" if $mech->success();
Now that I think of it, all that was missing from your first example (with 'xpath' key) was having the parameters wrapped inside of curly brackets {}. Without them, the synchronize key is ignored, and resulted in an infinite wait.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: WWW::Mechanize::Firefox clicking on a div doesn't work
by bbrown25 (Initiate) on Oct 26, 2014 at 21:38 UTC | |
by Loops (Curate) on Oct 28, 2014 at 02:20 UTC | |
by bbrown25 (Initiate) on Oct 28, 2014 at 21:47 UTC | |
by Corion (Patriarch) on Oct 29, 2014 at 08:02 UTC |