Simple strategy for choosing Selenium locators

Alexander Pushkarev
1 min readMay 11, 2020

--

One of the things an inexperienced test automation engineer struggle with when it comes to UI Test Automation is “what kind of Selenium locator I should use for a specific element”.

Note: I am no longer publishing professional posts on Medium, so this one may be outdated. Please check my blog at Hashnode: https://testclub.hashnode.dev/

Element locators that generated by tools usually are sub-optimal and a friend of mine Dmitry Rak has suggested a great locator selection strategy:

  • locate by id (if it is not generated automatically)
  • locate by name (which should be unique for a specific form)
  • locate by css (for all other cases except text)
  • xPath as a last choice (for all other complex cases and text search)

My personal preference is to insist on having a unique, non-generated id for each element we’re interested in at least in a test environment.

If you speak Russian — feel free to check the original post: https://lnkd.in/d55W2pX

PS

Did you enjoy this post? I think you might also find this video useful: https://www.youtube.com/watch?v=RVel7MZaSA0

It explains why test automation cannot fully replace testing.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Alexander Pushkarev
Alexander Pushkarev

Written by Alexander Pushkarev

Software engineer. Development-focused tester and test-focused developer. Interested in holistic view on testing, development and project management.

Responses (1)

Write a response