Which Selenium WebDriver locator is faster?

Zhimin Zhan
3 min readJan 27, 2021

According to this article on Medium: “Which locator is faster in identifying elements in Selenium?”, the order of Selenium Locators (fast to slow) is “ID, Name, CSS, XPath”.

Today I did a benchmark test to compare those 4 Selenium locators, I got quite different results. As we know, the time took to identify one web element is very much dependent on the page content. There are many factors that affect the results, such as the size and structure of HTML, the number of elements, …, etc. In other words, people get different results with different test data.

I planned to be as objective and realistic as possible.

  • Use the simplest form possible

The purpose is to test the raw locator speed. If using complex XPath expressions including XPath functions such as “contains(text(), ‘SPECIAL TEXT’)”, the result for XPath will be slow.

  • Realistic web pages

I used two common pages: Sign Up (simple) and Preferences (medium with many form fields) on a modern web site based on the Material design.

--

--

Zhimin Zhan

Test automation & CT coach, author, speaker and award-winning software developer. Help teams succeed with Agile/DevOps by implementing real Continuous Testing.