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
QA Leadership Summit - The AI-Native Edge: Leading the Future of QA image
QALS Summer 2026: a leadership summit to move beyond AI testing pilots and build production-ready, AI-first QA organizations - powered by the BrowserStack AI Test Platform and 25+ connected AI agents
MoT Foundation Certificate in Test Automation image
Unlock the essential skills to transition into Test Automation through interactive, community-driven learning, backed by industry expertise
This Week in Quality image
Debrief the week in Quality via a community radio show hosted by Simon Tomes and members of the community
Subscribe to our newsletter