Set selenium webdriver's default execution speed Set selenium webdriver's default execution speed selenium selenium

Set selenium webdriver's default execution speed


Don't use sleep!!!

public static WebElement findElement(WebDriver driver, By selector, long timeOutInSeconds) {    WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds);    wait.until(ExpectedConditions.presenceOfElementLocated(selector));    return findElement(driver, selector);}


Once there was a "setSpeed()" method for the Java bindings of Selenium WebDriver. But it was deprecated, because it makes no sense regarding browser automation.

Instead if the driver is "faster" than the loading of your elements or sth similar, you should always make intelligent use of waits to handle these cases.

To sum it up, there is currently no option to deliberately slow down execution within WebDriver itself. there is no other way currently to explicitly slow down steps of yours other than implement Thread.sleep()

BUT there are some other options that you might explore:

For example you could write your own method to click elements if you want to slow down clicking of elements:

public void clickElement(WebElement element) {    try {        Thread.sleep(1000);    } catch (InterruptedException e) {        e.printStackTrace();    }    element.click();}

if you wanted to slowdown the findElement method you could write another helper method:

public void findElement(By by) {    try {        Thread.sleep(1000);    } catch (InterruptedException e) {        e.printStackTrace();    }    driver.findElement(by);}

You could even write your own extended class from one of the WebDriver classes as is described here like this:

public class MyFirefoxDriver extends FirefoxDriver {@Overridepublic WebElement findElement(By by) {    try {        Thread.sleep(1000);    } catch (InterruptedException e) {        e.printStackTrace();    }    return by.findElement((SearchContext) this);}

You could write these methods for all executions that you want to slow down.


Under normal circumstances, when it looks for an element, Selenium keeps trying to find an element for up to however long as you've set the value of "implicitly wait". This means that if the element is found sooner than that, it will continue with test execution. I am no expert in Java, but in the code you provide I can't identify any bits that are looking for a drop-down item. Since a drop-down menu can be loaded long before the actual items inside it are loaded, I would wager that therein lies your issue: it's looking for the drop-down itself, finds it, stops waiting and starts trying to execute the rest of the test, which fails because the items weren't loaded yet. The solution therefore would be to look for the specific item you're trying to select. Unfortunately I am not well-versed enough in Java to provide you with the actual code solution.

As an aside, in my experience when exporting from Selenium IDE to something else you end up with tests that are almost, but not quite, entirely unlike what you expect. They could be doing what you expect them to, but they usually take shortcuts or at least a different approach than you would if you were to code the tests yourself.