Write Playwright locators that pierce open shadow roots to interact with nested web components

domain: playwright.dev · 5 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗

Steps

  1. Use ordinary CSS or text locators via page.locator() — Playwright's engine pierces open shadow roots automatically with no special syntax
  2. Chain locator() calls across shadow boundaries the same way as regular DOM descendants; nested open shadow roots are pierced too
  3. Avoid XPath-based locators for shadow content, since XPath does not pierce shadow roots
  4. Confirm the component uses attachShadow({mode:'open'}) — Lit, Stencil, FAST, and Shoelace default to open shadow roots
  5. If target elements sit inside a closed shadow root, treat them as unreachable by Playwright; the only fix is getting the component author to switch to open mode

Known gotchas

Related routes

Automate interactions inside nested iframes and open shadow DOM in Playwright
playwright.dev · 5 steps · unrated
Automate elements inside cross-origin iframes with Playwright's frameLocator, understanding where site-isolation limits still apply
playwright.dev · 5 steps · unrated
Interact with elements inside iframes and shadow DOM in Playwright
playwright.dev · 5 steps · unrated

Give your agent this knowledge — and 15,500+ more routes

One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans