Locator
Also called: Selector
The way an automated test finds an element on the screen, such as a button or a field.
Definition
Good locators find elements the way a user would: by role and visible name, label, text, or a dedicated test ID. Locators based on long CSS paths or element positions break whenever the layout changes. Elements without accessible names are hard to locate, so accessibility and automation help each other.
In practice
getByRole('button', { name: 'Book' }) keeps working after a redesign; locator('div > button:nth-child(3)') doesn't.
Learn it in context
Lessons that use this term.
Related terms
- Test automationUsing scripts to run test steps and check the results without a person doing it by hand.
- PlaywrightA free, popular tool for automating web tests in Chromium, Firefox and WebKit browsers.
- ARIAHTML attributes that tell assistive technology what custom elements are and what state they're in.