public function testUntilShouldWaitShouldThrowException() { $this->setExpectedException('SeleniumClient\\WebDriverWaitTimeoutException'); $this->_driver->findElement(By::id("btnAppendDiv"))->click(); $wait = new WebDriverWait(3); $label = $wait->until($this->_driver, "findElement", array(By::id("dDiv1-0"), true)); }
public function testDemo2() { //click button/get alert text $this->_driver->get($this->_testUrl); $this->_driver->findElement(By::id("btnAlert"))->click(); $this->assertEquals("Here is the alert", $this->_driver->getAlertText()); $this->_driver->acceptAlert(); //get main window handle $mainWindowHandle = $this->_driver->getCurrentWindowHandle(); //open popup window / handle its elements $this->_driver->findElement(By::id("btnPopUp1"))->click(); $this->_driver->switchTo()->getWindow("popup1"); $webElement = $this->_driver->waitForElementUntilIsPresent(By::id("txt1")); $webElement->sendKeys("test window"); $this->assertEquals("test window", $webElement->getAttribute("value")); $this->_driver->closeCurrentWindow(); $this->_driver->switchTo()->getWindow($mainWindowHandle); //get iframe / handle its elements $this->_driver->getFrame("iframe1"); $webElement = $this->_driver->waitForElementUntilIsPresent(By::id("txt1")); $webElement->sendKeys("test iframe"); $this->assertEquals("test iframe", $webElement->getAttribute("value")); $this->_driver->switchTo()->getWindow($mainWindowHandle); //wait for element to be present $this->_driver->findElement(By::id("btnAppendDiv"))->click(); $wait = new WebDriverWait(8); $label = $wait->until($this->_driver, "findElement", array(By::id("dDiv1-0"), true)); $this->assertEquals("Some content", $label->getText()); sleep(5); }
/** * Stops the process until an element is found * @param By $locator * @param Integer $timeOutSeconds * @return \SeleniumClient\WebElement */ public function waitForElementUntilIsPresent(By $locator, $timeOutSeconds = 5) { //We have to validate that timeOutSeconds is int, we have to add a new exception into the selenium exceptions and not use the exceptions that are outsite of the library //if ( !is_int($timeOutSeconds) ) { throw new Not_Int_Exception("wait_for_element_until_is_present", "time_out_seconds"); } $wait = new WebDriverWait($timeOutSeconds); $dynamicElement = $wait->until($this, "findElement", array($locator, TRUE)); return $dynamicElement; }
/** * Wait until current element's text equals specified * @param By $locator * @param String $targetText * @param Integer $timeOutSeconds * @throws WebDriverWaitTimeoutException * @return \SeleniumClient\WebElement */ public function waitForElementUntilIsPresentWithSpecificText(By $locator, $targetText, $timeOutSeconds = 5) { //We have to validate that timeOutSeconds is int, we have to add a new exception into the selenium exceptions and not use the exceptions that are outsite of the library //if ( !is_int($timeOutSeconds) ) { throw new Not_Int_Exception("wait_for_element_until_is_present", "time_out_seconds"); } $dynamicElement = null; $wait = true; $attempts = $timeOutSeconds; while ($wait) { $currentText = null; $webDriverWait = new WebDriverWait($timeOutSeconds); $dynamicElement = $webDriverWait->until($this, "findElement", array($locator, TRUE)); try { $currentText = $dynamicElement->getText(); } catch (SeleniumStaleElementReferenceException $ex) { //echo "\nError The Objet Disappear, Wait For Element Until Is Present With Specific Text\n"; } if ($currentText == $targetText) { $wait = false; } else { if ($attempts <= 0) { throw new WebDriverWaitTimeoutException("Timeout for waitForElementUntilIsPresentAndTextIsChange."); } } sleep(1); $attempts = $attempts - 1; } return $dynamicElement; }