locators
Installation
SKILL.md
Playwright Locator Conventions
Apply these locator rules whenever writing or reviewing Playwright code in this project. The priority ladder is strict — drop to a lower tier only when the higher tier is genuinely unavailable.
The Priority Ladder
Choose the highest tier that resolves the target element. Each lower tier is less stable and more likely to break on UI changes.
getByTestId('description-input')— preferred. Every interactive element should have adata-testid.getByRole('button', { name: 'Save' })— semantic role + accessible name.getByLabel('Description')— form field by its label.getByPlaceholder('Search...')— form field by placeholder.getByTitle('Delete')— element by title attribute.- Chained:
page.getByTestId('panel-edit').getByRole('button', { name: 'Save' })— narrow scope. - Class / id:
page.locator('#main-content'),page.locator('.sidebar'). getByText('Welcome')/getByAltText('logo')— brittle to copy/asset changes.- CSS / XPath:
page.locator('div > .item:nth-child(3)'), XPath strings — last resort, must include a comment explaining why no higher tier works.