Two MoTacon attendees are on the left. The MoTaacon logo is in the center, and to the right a prompt to Get Your Ticket.

Shadow DOM

Shadow DOM image
Shadow DOM is a web standard that allows a component to have its own isolated DOM tree, separate from the main document. It is one of the core technologies behind Web Components and is designed to encapsulate a component's internal structure, styles, and behaviour. This isolation prevents CSS and JavaScript outside the component from accidentally affecting its internals, while also preventing the component's implementation details from leaking into the rest of the page.

A Shadow DOM is attached to a host element through a shadow root, which can be either open or closed. An open shadow root can be accessed and inspected through JavaScript, while a closed shadow root hides its internal DOM from external scripts, making direct inspection and traversal impossible through standard browser APIs.

For software testers, Shadow DOM affects how automated tests locate and interact with elements. Standard locator strategies, such as CSS selectors or XPath, cannot directly access elements inside a closed shadow root. This means automation failures may be caused by component encapsulation rather than incorrect locators or timing issues. In many cases, improving testability involves architectural decisions, such as exposing open shadow roots in test environments, providing dedicated test APIs, or testing behaviour at a higher integration level instead of attempting to bypass encapsulation.

Explore MoT
Influence, from the other side of the table image
What I learned about influence by becoming a stakeholder
MoT Advanced Certificate in Test Automation image
Ascend to leadership roles by mastering strategic skills in automation strategy creation, planning and execution
Into The Motaverse image
Into the MoTaverse is a podcast by Ministry of Testing, hosted by Rosie Sherry, exploring the people, insights, and systems shaping quality in modern software teams.
Subscribe to our newsletter