Nearsoft\SeleniumClient\WebDriverWait::until PHP Method

until() public method

Stop current flow until specified condition is completed
public until ( $seleniumObject, String $method, array $args ) : mixed
$method String
$args array
return mixed
    public function until($seleniumObject, $method, array $args)
    {
        if (!isset($seleniumObject)) {
            throw new \Exception("seleniumObject parameter has not been initialized");
        } else {
            if (!isset($method)) {
                throw new \Exception("method parameter has not been initialized");
            }
        }
        $seconds = $this->_seconds;
        $elapsed = -1;
        $start = microtime(true);
        while ($elapsed < $seconds) {
            // the amount of time to sleep until the next whole second
            if ($elapsed > 0 && ($sleep = 1000000 * (1 - ($elapsed - (int) $elapsed))) > 0) {
                usleep($sleep);
            }
            try {
                $resultObject = call_user_func_array(array($seleniumObject, $method), $args);
                if ($resultObject !== null && $resultObject !== false) {
                    return $resultObject;
                }
            } catch (\Exception $ex) {
            }
            $elapsed = microtime(true) - $start;
        }
        $exMessage = "Timeout for specified condition caused by object of class: " . get_class($seleniumObject) . ", method invoked: " . $method . ".";
        if ($args != null && count($args) > 0) {
            $stringArgs = array();
            foreach ($args as $arg) {
                if (is_object($arg) && method_exists($arg, '__toString')) {
                    $stringArgs[] = $arg;
                } else {
                    if (is_object($arg) && !method_exists($arg, '__toString')) {
                        $stringArgs[] = get_class($arg);
                    } else {
                        $stringArgs[] = $arg;
                    }
                }
            }
            $exMessage .= " Arguments: <" . implode(">,<", $stringArgs) . ">";
        }
        throw new Exceptions\WebDriverWaitTimeout($exMessage);
    }

Usage Example

コード例 #1
0
 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);
 }
All Usage Examples Of Nearsoft\SeleniumClient\WebDriverWait::until