# Playwright locators break when the team picks them without enough UI context.

This guide explains where locator failures usually come from and how live element capture helps teams pick safer Playwright targets.

- Break down the common failure modes behind flaky locators.
- Compare CSS selectors, getByRole, and test ID strategies.
- Show how exact UI capture changes the decision quality.

## The main reasons Playwright locators break

Selectors fail when teams optimize for immediate convenience instead of durability. CSS paths often encode unstable structure, roles fail when accessible naming is inconsistent, and test IDs fail when governance is loose or absent.

The right choice depends on the exact element, the surrounding DOM, and how disciplined the product team is about markup.

## How to choose more durable locators

Start from the real UI artifact. Inspect the live element, compare strategies, and pick the locator that matches both resilience and team habits.

- Prefer semantic locators when the accessible contract is reliable.
- Use test IDs when the team enforces naming and ownership.
- Use CSS selectors carefully when structure and attributes are stable enough to justify it.

## Teach the problem, then point to the workflow that solves it.

This guide stays practical, then routes readers into the Playwright locator generator and flaky-test workflow pages.

## Frequently Asked Questions

**Is there one best Playwright locator?**  
No. The best locator depends on the element, the markup discipline of the team, and how likely the surrounding UI is to change.
