Batch 9 starts 10 Nov 2026  ·  Free demos from 3 Nov

Testing

Selenium locators: picking one that survives UI changes

1 min read

Selenium finds page elements through locators, and the choice of locator decides whether tests survive the next redesign. Locators based on page layout break whenever designers move things. Locators based on stable identifiers survive. The skill is picking the locator that is least likely to change for reasons unrelated to the feature under test.

Locator choices ranked by stability

  • Unique IDs are best, when developers provide them, since they exist precisely to identify the element.
  • Meaningful attributes, such as names and test-specific attributes, come next and rarely change by accident.
  • Visible text works for buttons and links, but breaks when wording changes, so use it sparingly.
  • Long paths through the page structure are the weakest option and should be a last resort.

When no stable locator exists, ask developers to add one. Testability is a team responsibility, not a tester workaround.

← Back to the blog Book a free demo →