Atlas › 13 Browser Automation with Playwright › Locator Strategies☰ Read as one page
Locator Strategies
7.1OverviewChoosing the right locator strategy is one of the highest-leverage decisions in test automation. Fragile locators are the leading cause of…7.2The Locator HierarchyPlaywright recommends locators in this priority order:7.3CSS and XPath: When You Need ThemPlaywright supports CSS and XPath for cases where semantic locators are insufficient:7.4Locator Strategy Comparison7.5Practical Example: Login Form7.6Key Takeaways- Prefer role-based locators (getByRole) — they mirror user behavior and survive refactoring - Use getByTestId when semantic locators are…