6

I need to be able to wait for one of multiple things that could happen to a page after a certain action is taken. Examples of these things are: URL changes, a certain title is set, certain content on the page appears, etc.

This explains how to wait - https://github.com/facebook/php-webdriver/wiki/HowTo-Wait. However, I need to be able to wait for multiple things at the same time. I want the waiting to stop once one of the conditions occur.

Is there a way to "or" during a wait (e.g. wait for URL to change OR title contains "foo" OR "bar" appears on the page, etc.)?

StackOverflowNewbie
  • 39,403
  • 111
  • 277
  • 441

1 Answers1

7

In the same link you posted, look for the "Custom conditions" section, i.e.:

$driver->wait()->until(
    function () use ($driver) {
        $elements = $driver->findElements(WebDriverBy::cssSelector('li.foo'));

        return count($elements) > 5;
    },
    'Error locating more than five elements'
);

Note the use of findElements in the code example. When nothing is found, an empty array will be returned. If only one of three elements must be visible, you do something like:

$driver->wait()->until(
    function () use ($driver) {
        $elements1 = $driver->findElements(WebDriverBy::cssSelector('li.foo1'));
        $elements2 = $driver->findElements(WebDriverBy::cssSelector('li.foo2'));
        $elements3 = $driver->findElements(WebDriverBy::cssSelector('li.foo3'));

        return count($elements1) + count($elements2) + count($elements3) > 0;
    },
    'Error locating at least one of the elements'
);
Benjamin Loison
  • 3,782
  • 4
  • 16
  • 33
misterjake
  • 159
  • 5