-
-
Save djangofan/2031925 to your computer and use it in GitHub Desktop.
selenium-webdriver wait
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public WebElement waitFindElement(WebDriver drv, By by, long timeout, long interval) | |
{ | |
long start = System.currentTimeMillis(); | |
while(true){ | |
try{ | |
return drv.findElement(by); | |
} catch(NoSuchElementException nse) { | |
if(System.currentTimeMillis()-start>=timeout) | |
{ | |
throw new Error("Timeout reached and element["+by+"]not found"); | |
} | |
else { | |
try { | |
synchronized(this){ | |
wait(interval); | |
} | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment