/** * An expectation for checking that an element, not known to be present on the DOM * * @param WebDriverBy $by The element to be checked. * @param WebDriverElement $parentElement The element to be under. * @return CustomExpectedCondition<bool> true when element not * present in DOM. */ public static function elementDestroyed(WebDriverBy $by, RemoteWebElement $parentElement = null) { return new CustomExpectedCondition(function ($driver) use($element) { $els = $parentElement ? $parentElement->findElements($by) : $driver->findElements($by); return count($els) === 0; }); }
/** * Wait untill given element is present in DOM */ static function waitUntilPresent(\WebDriverBy $elementsBy, \RemoteWebElement $parentElement = NULL, $waitSeconds = MEDIUM_WAIT) { $expireSeconds = 0; $present = false; while ($expireSeconds < $waitSeconds) { $els = $parentElement ? $parentElement->findElements($elementsBy) : WebDriver::instance()->findElements($elementsBy); if (count($els) > 0) { $present = true; break; } sleep(1); $expireSeconds++; } if (!$present) { $value = $elementsBy->getValue(); throw new \Exception("Unexpectedly elements \"{$value}\" was not found present after {$waitSeconds} seconds wait"); } }