Reputation: 37766
When I use Selenium RC there is a method setSpeed as:
selenium.setSpeed("500");
What is the way to control speed of browser in Selenium WebDriver?
Upvotes: 8
Views: 19441
Reputation: 204
There is no straight forward way. But there is a hack that you can use, you can override methods of webdriver and introduce a explicit sleep to slow down your tests eg. overriding findElement method
public class _WebDriver extends FirefoxDriver {
@Override
public WebElement findElement(By by) {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return by.findElement((SearchContext) this);
}
}
Upvotes: 6
Reputation: 2021
Even better might be to use the webdriver FluentWait class alongside with ExpectedCondition. Sample can be found here: http://www.summa-tech.com/blog/2011/10/10/using-page-objects-with-selenium-and-web-driver-20/
Upvotes: 0
Reputation: 11326
You can use Thread.Sleep(500)
(or equivalent) in whatever language you are using to run webdriver. This will cause the thread to pause for an exact number of milliseconds.
Alternatively you can use explicit or implicit waits described here.
Explicit waits allow you to define an ExpectedCondition
. Webdriver will check the condition every 500 milliseconds until it returns true, (after which execution will resume immediately).
Implicit waits cause webdriver to keep retry attempting to locate something in the DOM. Execution will resume immediately once the element is found.
Note that neither implicit nor explicit waits will guarantee a 500 millisecond pause.
Upvotes: 4
Reputation: 27486
There is no longer any way to control the speed of each "step" in Selenium WebDriver. At one time, there was a setSpeed()
method on the Options
interface (in the Java bindings; other bindings had similar constructs on their appropriately-named objects), but it was deprecated long, long ago. The theory behind this is that you should not need to a priori slow down every single step of your WebDriver code. If you need to wait for something to happen in the application you're automating, you should be using an implicit or explicit wait routine.
Upvotes: 12