++ed by:

17 PAUSE users
23 non-PAUSE users.

George S. Baugh
and 46 contributors


Selenium::Waiter - Provides a utility wait_until function


version 1.36


    use Selenium::Waiter qw/wait_until/;
    my $d = Selenium::Remote::Driver->new;

    my $div = wait_until { $d->find_element('div', 'css') };



Exported by default, it takes a BLOCK (required) and optionally a hash of configuration params. It uses a prototype to take its arguments, so usage looks look like:

    use Selenium::Waiter;
    my $div = wait_until { $driver->find_element('div', 'css') };

The above snippet will search for css=div for thirty seconds; if it ever finds the element, it will immediately return. More generally, Once the BLOCK returns anything truthy, the wait_until will stop evaluating and the return of the BLOCK will be returned to you. If the BLOCK never returns a truthy value, we'll wait until the elapsed time has increased past the timeout and then return an empty string ''.

Achtung! Please make sure that the BLOCK you pass in can be executed in a timely fashion. For Webdriver, that means that you should set the appropriate implicit_wait timeout low (a second or less!) so that we can rerun the assert sub repeatedly. We don't do anything fancy behind the scenes: we just execute the BLOCK you pass in and sleep between iterations. If your BLOCK actively blocks for thirty seconds, like a find_element would do with an implicit_wait of 30 seconds, we won't be able to help you at all - that blocking behavior is on the webdriver server side, and is out of our control. We'd run one iteration, get blocked for thirty seconds, and return control to you at that point.


PLEASE check the return value before proceeding, as we unwisely suppress any attempts your BLOCK may make to die or croak. The BLOCK you pass is called in a "try" in Try::Tiny, and if any of the invocations of your function throw and the BLOCK never becomes true, we'll carp exactly once at the end immediately before returning false. We overwrite the death message from each iteration, so at the end, you'll only see the most recent death message.

    # warns once after thirty seconds: "kept from dying";
    wait_until { die 'kept from dying' };

The output of dies from each iteration can be exposed if you wish to see the massacre:

    # carps: "kept from dying" once a second for thirty seconds
    wait_until { die 'kept from dying' } debug => 1;

Timeouts and Intervals

You can also customize the timeout, and/or the retry interval between iterations.

    # prints hi three four times at 0, 3, 6, and 9 seconds
    wait_until { print 'hi'; '' } timeout => 10, interval => 3;




Please report any bugs or feature requests on the bugtracker website https://github.com/teodesian/Selenium-Remote-Driver/issues



Current Maintainers:

  • Daniel Gempesaw <gempesaw@gmail.com>

  • Emmanuel Peroumalnaïk <peroumalnaik.emmanuel@gmail.com>

Previous maintainers:

  • Luke Closs <cpan@5thplane.com>

  • Mark Stosberg <mark@stosberg.com>

Original authors:

  • Aditya Ivaturi <ivaturi@gmail.com>


Copyright (c) 2010-2011 Aditya Ivaturi, Gordon Child

Copyright (c) 2014-2017 Daniel Gempesaw


