Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void waitUntilCountChanges() {
- WebDriverWait wait = new WebDriverWait(getDriver(), 5);
- wait.until(new ExpectedCondition<Boolean>() {
- public Boolean apply(WebDriver driver) {
- int elementCount = driver.findElement(By.xpath("xxxx")).size();
- if (elementCount > 1)
- return true;
- else
- return false;
- }
- });
- }
- public function spin ($lambda, $wait = 60) {
- for ($i = 0; $i < $wait; $i++) {
- try {
- if ($lambda($this)) {
- return true;
- }
- } catch (Exception $e) {
- // do nothing
- }
- sleep(1);
- }
- $backtrace = debug_backtrace();
- throw new Exception(
- "Timeout thrown by " . $backtrace[1]['class'] . "::" . $backtrace[1]['function'] . "()n" .
- $backtrace[1]['file'] . ", line " . $backtrace[1]['line']
- );
- }
- $this->spin(function($context) {
- return ($context->getSession()->getPage()->findById('example')->isVisible());
- });
- start_time=now
- count=number of elements
- while count < X:
- count=number of elements
- if now - start_time > timeout
- exit loop
Add Comment
Please, Sign In to add comment