Locator Strategies
Playwright offers one of the most powerful locator engines in the testing ecosystem.
Recommended Locator Priority
getByRole()
getByTestId()
getByText()
CSS / XPath (last resort)
Why XPath Is Discouraged
- Easily breaks with UI changes
- Hard to maintain
- Low readability
- Causes flaky tests
Playwright Locators Are
- More stable
- Easier to read
- Auto-wait enabled