public function testDemo2() { //click button/get alert text $this->_driver->get($this->_testUrl); $this->_driver->findElement(By::id("btnAlert"))->click(); $alert = $this->_driver->switchTo()->alert(); $this->assertEquals("Here is the alert", $alert->getText()); $alert->accept(); //get main window handle $mainWindowHandle = $this->_driver->getWindowHandle(); //open popup window / handle its elements $this->_driver->findElement(By::id("btnPopUp1"))->click(); $this->_driver->switchTo()->window("popup1"); $webElement = $this->_driver->waitForElementUntilIsPresent(By::id("txt1")); $webElement->sendKeys("test window"); $this->assertEquals("test window", $webElement->getAttribute("value")); $this->_driver->close(); $this->_driver->switchTo()->window($mainWindowHandle); //get iframe / handle its elements $this->_driver->switchTo()->frame("iframe1"); $webElement = $this->_driver->waitForElementUntilIsPresent(By::id("txt1")); $webElement->sendKeys("test iframe"); $this->assertEquals("test iframe", $webElement->getAttribute("value")); $this->_driver->switchTo()->window($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); }
public function testUntilShouldWaitShouldThrowException() { $this->setExpectedException('Nearsoft\\SeleniumClient\\Exceptions\\WebDriverWaitTimeout'); $this->_driver->findElement(By::id("btnAppendDiv"))->click(); $wait = new WebDriverWait(3); $label = $wait->until($this->_driver, "findElement", array(By::id("dDiv1-0"), true)); }
/** * Stops the process until an element is found * @param By $locator * @param Integer $timeOutSeconds * @return Nearsoft\SeleniumClient\WebElement */ public function waitForElementUntilIsPresent(By $locator, $timeOutSeconds = 5) { $wait = new WebDriverWait($timeOutSeconds); $dynamicElement = $wait->until($this, "findElement", array($locator, true)); return $dynamicElement; }