Everyone who works in test automation probably heard or used the terms ‘selector’ and ‘locator’. I was thinking, what is the difference between these two? They seem closely related, however they are not actually the same thing.
Locators
A locator is an abstraction that defines how your automation tool should find an element in the user interface.
We can think of it as an instruction or query that tells the automation engine “here is how to find the element I want to interact with”. Locators are part of the test framework’s API and usually wrap or reference a selector behind the scene.
Locator example (Selenium with Python)

in the above example:
– By.ID is the locator strategy (a method for locating elements)
– “login-button” is the selector value
– Together, they form a locator that Selenium can use to find the element
In a nutshell:
A locator = (strategy + selector)
Selectors
A selector is a pattern or expression used to identify an element – commonly in the form of CSS selectors, XPath expressions, or accessibility attributes.
Selectors describe what element you’re looking for within the DOM
CSS Selector examples

XPath example

Selectors come from web technologies, not from the automation framework itself. They’re a web standard and frameworks like Selenium, Playwright, etc use them under the hood to actually locate elements.
A locator wraps or uses a selector internally. When you write a locator, you’re telling the framework which selector type to use and how to apply it.
Conclusion

Enjoyed this article? Make sure to subscribe to my YouTube Channel for more Test Automation tutorials, and follow me on LinkedIn and Twitter for regular insights.
Looking to improve your test automation skills?
I’ve created a personalized 1-on-1 Mentoring program refined to boost YOUR CURRENT skills. Reach out at iamrv@razvanvancea.ro for more details and together will create a learning path adapted to your skills and goals that you are aiming for, in a timely-efficient manner🚀
