Selenium performance tips

2 comments, 1 share, 626 points
Selenium performance tips

Selenium performance tips

Couple of days ago we had an article : How to get selenium to wait for ajax response , but I feel here is still a lot to discuss about ajax and performance .

Ajax typical flow:

ajax typical flow

You always need to wait for ….

  • Page loading
  • Element appereance
  • Element visibility
  • Element disappearance
  • Alert or popup dialog
  • New window
  • Text changes
  • Element style changes

WebDriver waits for page loading

  • By default page is loaded synchronously
  • No need to use waitForPageToLoad


  • Waiting is broken for long polling and some other techniques

You can avoid waiting manually

new HtmlUnitDriver(){
protected WebClient modifyWebClient(WebClient client){
WebClient noWaitClient = super.modifyWebClient(client);
noWaitClient.setRefreshHandler(new WaitingRefreshHandler());
return noWaitClient;
FirefoxProfile fp = new FirefoxProfile();
fp.setPreference(“web driver.load.strategy”, “unstable”);

WebDriver works with DOM

  • webdriver works with domEverything is dynamic
  • Complex unreliable structure
  • JavaScript libraries
  •  Third-party widgets
  • Rules are broken sometimes






DOM element workflow

dom element workflow


WebDriver is clever enough

driver.manage().timeouts().implicitlyWait(10, TimeUnit.seconds);
webdriver implicit wait


  • Waiting on browser side
  • Can’t stop earlier
  • findElements wait for at least one element
  •  May become hidden cause of long tests
  •  Doesn’t work for element presence check
  • Works for all findXXX methods transparently

Manual wait is available

private void waitForSuggestions(){
new WebDriverWait(driver, 30).until(new Predicate<WebDriver>() {
public boolean apply(WebDriver webDriver){
By selector = by.cssSelector(“selector”);
return webDriver.findElement(selector).isDisplayed();
manual wait

Lots of ready to use wait conditions

WebDriverWait wait = new WebDriverWait(driver, 30);

Fluent waits for tuned configurations

//waiting 30 seconds for an element to be present on the page,
// check for its presence once every 3 seconds.

Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
             .withTimeout(30, TimeUnit.SECONDS)
              .poolingevery(3, TimeUnit.SECONDS)

WebElement foo = wait.until(new Function<WebDriver, WebElement>(){
public WebElement apply(WebDriver driver){

return driver.findElement(“foo”);

fluent wait

Mouse operations

  • You can click on any visible element
  • OS events are emulated
  • DOM events are processed as always
  • Click is performed in the center of element area
  • Autoscrolling is performed for click but is not reliable

This are just couple of the Selenium performance tips , but we are going to discuss more in some further articles.

We will be covering :

  • Keyboard operation
  • Speed up type big amount of text
  • Actions for experts 🙂 and more …

Happy testing!

Like it? Share with your friends!

2 comments, 1 share, 626 points
Test engineer


Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.