Manuals / Playwright with Python / Chapter 29
Part 4 · Advanced Techniques · advanced · ~40 min · Chapter 29 of 61
21. Shadow DOM & Complex Components
Piercing shadow DOM Playwright's locators automatically pierce open shadow DOM by default — no special syntax needed in most cases: # Works transparently even if "custom-button" uses shadow DOM internally page.locator("custom-button").get_by_text("Submit").click() Pointers: This "just works" behavior is a genuine advantage over older tools, which often required manually accessing .shadowRoot via J
Step 1 of 2
Piercing shadow DOM
Playwright's locators automatically pierce open shadow DOM by default — no special syntax needed in most cases: Pointers: This "just works" behavior is a genuine advantage over older tools, which often required manually accessing .shadowRoot via JavaScript execution to reach shadow DOM content at all.
Try it
Run / study this snippet
# Works transparently even if "custom-button" uses shadow DOM internally
page.locator("custom-button").get_by_text("Submit").click()Chapter learning outcomes
- Piercing shadow DOM
- Handling custom web components
Clear these before you leave
Side quest
21. Shadow DOM & Complex Components deliverable
Apply one idea from “Piercing shadow DOM” in a small script or note.