How to master reliable XPath locators for your automated tests

Eugene Truuts
6 min readSep 3, 2023

I’ve observed that the XPath locators mastering can challenge many individuals, including junior and mid-level automation engineers. This issue often stems from various sources, such as:

  • Inexperience in mastering locators for automation.
  • A reliance on browser extensions that generate “ready-to-use” locators, which are then copied and pasted into test code.
  • A perception that XPath Locators are inherently unreliable leads to their avoidance of test scripts.
  • It’s laziness because your developers added test attributes for everything in the DOM.

In this guide, I provided approaches and examples to help you build reliable XPath Locators for your automated tests.

XPath mastering

Let’s begin with the Wikipedia main page and imagine that you need to verify the presence of the ‘Free textbooks’ text within the Wikibooks block in our automated test.

The most straightforward approach is copying the pre-built XPath locator using the browser’s developer tools, as shown in this image.

--

--

Eugene Truuts
Eugene Truuts

Written by Eugene Truuts

🇪🇪🇺🇸SDET at RingCentral, Inc. 👨🏻‍🎓B.Sc. in Computer Science. Talks about testing, automation, Playwright framework, JavaScript, GitLab, productivity,

No responses yet