Skip to main content

CSS vs. XPath

NOTE: This is part 1 of 3. For the second installment, go here. For the last installment, go here.

Intro

One of the most heated and subjective conversations in the Selenium community is which locator strategy is better, often circling around two -- XPath and CSS. People in favor of CSS say that it is more readable and faster (especially when running against Internet Explorer). While those in favor of XPath tout its ability to transverse the page (while CSS cannot).

With such a divide, it can be hard to determine the best approach for you and your team. Especially when most of these claims are outdated.

A Solution

Let's cut through the noise by running our own performance tests across all major browsers to see how CSS and XPath stack up and fall down. Then we will be able to determine a more helpful locator strategy.

About The Author

Dave Haeffner is the original writer of Elemental Selenium -- a free, once weekly Selenium tip newsletter that's read by thousands of testing professionals. He also created and maintains the-internet (an open-source web app that's perfect for writing automated tests against).

Dave has helped numerous companies successfully implement automated acceptance testing; including The Motley Fool, ManTech International, Sittercity, and Animoto. He is also an active member of the Selenium project and has spoken at numerous conferences and meetups around the world about automated acceptance testing.

Dave Haeffner profile picture