You are here

public function Element::waitFor in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/behat/mink/src/Element/Element.php \Behat\Mink\Element\Element::waitFor()

Waits for an element(-s) to appear and returns it.

Parameters

int|float $timeout Maximal allowed waiting time in seconds.:

callable $callback Callback, which result is both used as waiting condition and returned.: Will receive reference to `this element` as first argument.

Return value

mixed

Throws

\InvalidArgumentException When invalid callback given.

Overrides ElementInterface::waitFor

File

vendor/behat/mink/src/Element/Element.php, line 119

Class

Element
Base element.

Namespace

Behat\Mink\Element

Code

public function waitFor($timeout, $callback) {
  if (!is_callable($callback)) {
    throw new \InvalidArgumentException('Given callback is not a valid callable');
  }
  $start = microtime(true);
  $end = $start + $timeout;
  do {
    $result = call_user_func($callback, $this);
    if ($result) {
      break;
    }
    usleep(100000);
  } while (microtime(true) < $end);
  return $result;
}