Ripon Al Wasim
Ripon Al Wasim

Reputation: 37766

Is there any method in WebDriver with Java for controlling speed of browser?

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

Answers (4)

moiz virani
moiz virani

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

Arek
Arek

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

shamp00
shamp00

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

JimEvans
JimEvans

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

Related Questions