Reputation: 419
How can I make the selenium driver in Java wait on nothing for a few seconds, just to pause the driver?
Upvotes: 1
Views: 5849
Reputation: 197
This is what I'm using in Python
import time
print "Start : %s" % time.ctime()
time.sleep( 5 )
print "End : %s" % time.ctime()
Output :
Start : Tue Feb 17 10:19:18 2009
End : Tue Feb 17 10:19:23 2009
Upvotes: 0
Reputation: 66
fun WebDriver.delay(timeout: Duration) {
val until = System.currentTimeMillis() + timeout.toMillis()
WebDriverWait(this, timeout).until {
return@until until <= System.currentTimeMillis()
}
}
It's kotlin extendsions code. normally method like this:
fun delay(driver: WebDriver, timeout: Duration) {
val until = System.currentTimeMillis() + timeout.toMillis()
WebDriverWait(driver, timeout).until {
return@until until <= System.currentTimeMillis()
}
}
Upvotes: 0
Reputation: 451
There are different ways to wait using selenium:
WebDriver driver = new FirefoxDriver(); driver.get("http://somedomain/url_that_delays_loading"); WebElement myDynamicElement = (new WebDriverWait(driver, 10)).until(ExpectedConditions.presenceOfElementLocated(By.id("myDynamicElement")));
This waits up to 10 seconds before throwing a TimeoutException or if it finds the element will return it in 0 - 10 seconds
WebDriver driver = new FirefoxDriver(); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); driver.get("http://somedomain/url_that_delays_loading"); WebElement myDynamicElement = driver.findElement(By.id("myDynamicElement"));
Also you can use Thread.sleep(), this is not recommended but if you are just debugging this is the easiest way.
You can take a look to the Selenium documentation to understand better how to use waits.
Upvotes: 3
Reputation: 419
try {
Thread.sleep(4000);
} catch (InterruptedException e) {
e.printStackTrace();
}
Seemed to do the trick.
Upvotes: 0