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

$test_to_execute = 2
i get exactly the same result.


In reply to Re^4: How to control two tabs at the same time with WWW::Mechanize::Firefox by mascip
in thread How to control two tabs at the same time with WWW::Mechanize::Firefox by mascip

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.