Manuals / Playwright with Python / Chapter 11

Part 2 · Core Interactions · beginner · ~60 min · Chapter 11 of 61

5. Locators Deep Dive

This is the most important chapter in the entire manual — nearly everything else builds on writing good locators. These are "user-facing" locators — they find elements the way a real user (or screen reader) would identify them, rather than by internal implementation details like CSS classes.

Path progress
17%

Step 1 of 13

Overview

This is the most important chapter in the entire manual — nearly everything else builds on writing good locators. These are "user-facing" locators — they find elements the way a real user (or screen reader) would identify them, rather than by internal implementation details like CSS classes. This is deliberate philosophy, not just convenience: implementation details (class names, DOM structure) change often as developers refactor CSS/markup, but the role and visible text of a button rarely change. Locators built on them break far less often.

OverviewDrag stickies · tap for tips
Study mapDrag stickies · tap for tipsKeep it shortdrag · tap →Name the waitdrag · tap →Scope locatorsdrag · tap →Trace when stuckdrag · tap →One browser firstdrag · tap →Isolate statedrag · tap →Assert the UIdrag · tap →Retry wiselydrag · tap →Seed datadrag · tap →Close the loopdrag · tap →Keep it shortdrag · tap →Name the waitdrag · tap →Scope locatorsdrag · tap →Trace when stuckdrag · tap →One browser firstdrag · tap →Isolate statedrag · tap →Pathwise hackdrag · tap →Page under testdrag · tap →Multi-browserdrag · tap →Automation pathdrag · tap →Tooling nodedrag · tap →

Quick check

Preferred Playwright locator style is…

Was this step clear?
Chapter learning outcomes
  • CSS and XPath locators
  • Chaining and filtering locators
  • Locator strictness and auto-retry

Clear these before you leave

Side quest

5. Locators Deep Dive deliverable

Apply one idea from “Overview” in a small script or note.