in reply to Re^3: How to control two tabs at the same time with WWW::Mechanize::Firefox
in thread How to control two tabs at the same time with WWW::Mechanize::Firefox
Wait for one particular element, yes that could be it.
* time passes and i search *
I found it !
I had seen it several weeks ago, but had not understood at the time, and then forgotten.
In the cookbook, HERE.
Here is my version, and it doesn't work. When i call the WWW::Mechanize::Firefox::is_visible() subroutine, it stops in the middle and says "10 elements found for '//a@class="kl"' at test_events_synchronize.pl line 51."
Apparently this happens in find_link_dom(), and it highlights many elements in the window. What am i doing wrong? Here is my code :
#!/usr/bin/perl use 5.012003; # Perl version requirement use strict; use warnings; #comment before releasing use autodie 2.10; use Carp 1.25; use Perl6::Say 0.16; use Readonly 1.03; use Scalar::Util qw( dualvar ); # ##### use WWW::Mechanize::Firefox 0.59; use Time::HiRes 1.9721 qw( time ); # where is my Firefox executable ? Readonly my $FIREFOX_FOLDER => 'C:\Program Files\Mozilla Firefox\firefox.exe'; # ###### # URL address of the two pages that we want to open in two tabs Readonly my $URL => 'https://www.google.ca/search?tbm=isch&hl=en&sourc +e=hp&biw=1400&bih=866&q=big+images&gbv=2&oq=big+images&aq=f&aqi=g10&a +ql=&gs_sm=3&gs_upl=1564l3028l0l3402l10l10l0l0l0l0l142l1032l4.6l10l0&g +s_l=img.3..0l10.1564l3028l0l3403l10l10l0l0l0l0l142l1032l4j6l10l0'; # start time my $t_start = time; # start browser 1 my $browser = WWW::Mechanize::Firefox->new( # launch Firefox if it is not already running launch => $FIREFOX_FOLDER, # events to wait for, before continuing after get()ing a page # events => ['DOMContentLoaded'], synchronize => 0, ); croak 'Could not initialize the browser' if !$browser->success(); say '# Browser is now ready to go'; # open page $browser->get( $URL ); croak 'Could not open the page' if !$browser->success(); say '# Page opened'; my $test_to_execute = 1; if( $test_to_execute == 1 ) { # wait until one particular element appears my $retries = 10; while ($retries-- && ! $browser->is_visible( xpath => '//a[@class="kl"]' )) { sleep 1; }; die "Timeout" unless $retries; } elsif( $test_to_execute == 2 ) { my $test_is_visible = $browser->is_visible( xpath => '//a[@class=" +kl"]' ); say $test_is_visible; } # print time passed my $t_passed = dualvar time - $t_start, 'time passed'; say "$t_passed = " . ($t_passed+0); # stop the program, so i can check which pages have been opened say '# done !'; my $stop = <ARGV>
PS : if is set
i get exactly the same result.$test_to_execute = 2
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: How to control two tabs at the same time with WWW::Mechanize::Firefox
by Corion (Patriarch) on Mar 11, 2012 at 22:07 UTC | |
by mascip (Pilgrim) on Mar 12, 2012 at 00:00 UTC | |
by mascip (Pilgrim) on Mar 12, 2012 at 12:02 UTC |