Skip to content

Instantly share code, notes, and snippets.

@djangofan
Forked from jarib/wd.rb
Created March 13, 2012 21:43
Show Gist options
  • Save djangofan/2031925 to your computer and use it in GitHub Desktop.
Save djangofan/2031925 to your computer and use it in GitHub Desktop.
selenium-webdriver wait
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