# Locators > **When to use**: Every time you need to find an element on the page. Start here before reaching for CSS or XPath. > **Prerequisites**: [core/configuration.md](configuration.md) ## Quick Reference ```typescript // Priority order — use the first one that works: page.getByRole("button", { name: "Submit" }) // 1. Role (default) page.getByLabel("Email address") // 2. Label (form fields) page.getByText("Welcome back") // 3. Text (non-interactive) page.getByPlaceholder("Search...") // 4. Placeholder page.getByAltText("Company logo") // 5. Alt text (images) page.getByTitle("Close dialog") // 6. Title attribute page.getByTestId("checkout-summary") // 7. Test ID (last semantic option) page.locator("css=.legacy-widget >> internal:role=button") // 8. CSS/XPath (last resort) ``` ## Patterns ### Role-Based Locators (Default Choice) **Use when**: Always. This is your starting point for every element. **Avoid when**: The element has no ARIA role and adding one is outside your control. Role-based locators mirror how assistive technology sees your page. They survive refactors, class renames, and component library swaps. **TypeScript** ```typescript import { test, expect } from "@playwright/test" test("role-based locators cover most UI elements", async ({ page }) => { await page.goto("/dashboard") // Buttons — matches