Member-only story
Testing web apps isnât always a walk in the park, especially when you encounter Shadow DOM elements. If youâve ever been stuck wondering why your test scripts are unable to interact with certain elements, chances are youâre dealing with this pesky beast. đ
In my journey as a QA Engineer, Iâve faced these challenges head-on using Cypress, Playwright, and Selenium, and let me tell you, handling Shadow DOMs can feel like dealing with a secret club where only a few elements have access. But donât worry â Iâm here to show you how to get in! đĄ
What is Shadow DOM? đ
Shadow DOM is a way for web components to encapsulate and hide their internal structure. Itâs great for developers, but for testers? Not so much. Since the DOM structure is isolated, accessing and interacting with Shadow DOM elements using traditional methods becomes tricky.

The Problem with Shadow DOM in Automation đ
Standard queries like getElementById
or cy.get
will not penetrate the Shadow DOM. So, even though you see the element on your browser, your scripts canât directly reach it. đ This means we need to pierce through the shadow boundary and access those elements manually.
But donât worry! Most frameworks like Cypress, Playwright, and Selenium offer ways to handle Shadow DOM.
Cypress đ
While Cypress is fantastic for many things, handling Shadow DOM requires a little extra effort. Hereâs how I tackled it:
cy.get('parent-selector').shadow().find('shadow-element-selector').click();
Cypress added native support for Shadow DOM handling using .shadow()
. This tells Cypress to access the Shadow DOM and interact with elements within. Here's a real-world example:
cy.get('custom-component')
.shadow()
.find('button')
.click();
Pro Tip đĄ: Make sure to confirm that the component youâre testing indeed uses Shadow DOM! Not all custom elements do.
Playwright đ
Playwright also has Shadow DOM handling built into its query system. Using Node.js, you can fetch and interact with Shadow DOM elements byâŚ