protected function wait_for_text($selector, $text) { self::$driver->wait(2)->until(WebDriverExpectedCondition::textToBePresentInElement(WebDriverBy::cssSelector($selector), $text)); }
/** * Waits up to $timeout seconds for the given string to appear on the page. * Can also be passed a selector to search in. * If the given text doesn't appear, a timeout exception is thrown. * * ``` php * <?php * $I->waitForText('foo', 30); // secs * $I->waitForText('foo', 30, '.title'); // secs * ?> * ``` * * @param string $text * @param int $timeout seconds * @param null $selector * @throws \Exception */ public function waitForText($text, $timeout = 10, $selector = null) { if (!$selector) { $condition = WebDriverExpectedCondition::textToBePresentInElement(WebDriverBy::xpath('//body'), $text); $this->webDriver->wait($timeout)->until($condition); return; } $condition = WebDriverExpectedCondition::textToBePresentInElement($this->getLocator($selector), $text); $this->webDriver->wait($timeout)->until($condition); }
/** * Wait and validate a text to be visible in an element. * * @param $text * @param $selector string The element's CSS selector. * * @throws \Exception * * @return $this */ public function seeText($text, $selector) { $this->waitUntil(WebDriverExpectedCondition::textToBePresentInElement(WebDriverBy::cssSelector($selector), $text)); return $this; }