Use Chained Locator to Speed Up Selenium WebDriver Tests

How to speed up your Selenium WebDriver scripts with Chained Locators

Courtney Zhan


My father’s article “Optimize Selenium WebDriver Automated Test Scripts: Speed” is a well-received one, featured on Geek Culture. It contains some practical tips to make your Selenium tests run faster.

In this article, I will share another speed optimization tip for Selenium WebDriver tests.

Task: Locate a “queue” link on W3C WebDriver page

There are three “queue” links (with that exact text) on the W3C WebDriver page. The reason I chose this page: it is quite large, 1.8MB in size. So, the time-saving difference is more noticeable.

Please note the purpose of this exercise to solely find out potential time-saving gains using chained-locators.

Let’s see the speed differences first.

First Version:

Timing: 0.83 Seconds.

exeuction result in TestWise

Optimized Version

Timing: 0.02 Seconds, ~40 times faster that the version above. Wow!

exeuction result in TestWise


The test design for the first version:

  • Find all the links with exact text “queue”
  • Choose the selected one, e.g. the second one

The test design for the optimized version:

  • Find one of its parent node by id, in this case, input-state
  • From the parent node, locate the link