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
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 "
clicked" if $mech->success();