/** * Waits up to $timeout seconds for the given element to be visible on the page. * If element doesn't appear, a timeout exception is thrown. * * ``` php * <?php * $I->waitForElementVisible('#agree_button', 30); // secs * $I->click('#agree_button'); * ?> * ``` * * @param $element * @param int $timeout seconds * @throws \Exception */ public function waitForElementVisible($element, $timeout = 10) { $condition = WebDriverExpectedCondition::visibilityOfElementLocated($this->getLocator($element)); $this->webDriver->wait($timeout)->until($condition); }
/** * @Then /^I should see success message$/ */ public function iShouldSeeSuccessMessage() { self::$webDriver->wait(20, 1000)->until(WebDriverExpectedCondition::visibilityOfElementLocated(WebDriverBy::className('success-message'))); }
/** * An expectation for checking an element is visible and enabled such that you * can click it. * * @param WebDriverBy $by The locator used to find the element * @return WebDriverExpectedCondition<WebDriverElement> The WebDriverElement * once it is located, visible and clickable */ public static function elementToBeClickable(WebDriverBy $by) { $visibility_of_element_located = WebDriverExpectedCondition::visibilityOfElementLocated($by); return new WebDriverExpectedCondition(function ($driver) use($visibility_of_element_located) { $element = call_user_func($visibility_of_element_located->getApply(), $driver); try { if ($element !== null && $element->isEnabled()) { return $element; } else { return null; } } catch (StaleElementReferenceException $e) { return null; } }); }
/** * Wait and validate an element to be visible. * * @param $selector * * @throws \Exception * * @return $this */ public function see($selector) { $this->waitUntil(WebDriverExpectedCondition::visibilityOfElementLocated(WebDriverBy::cssSelector($selector))); return $this; }