Shadow DOM with Puppeteer

Learn how to automate the Shadow DOM scenario using Google Puppeteer. This page provides code examples and links to the interactive practice component.

Puppeteer Code Examplejavascript
// Puppeteer - Shadow DOM
const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  await page.goto('https://xqa.io/practice/shadow-dom');
  
  // Access shadow root
  const shadowInput = await page.evaluateHandle(() => {
    return document.querySelector('#shadow-host').shadowRoot.querySelector('input');
  });
  await shadowInput.type('Hello Shadow DOM');
  
  await browser.close();
})();

How It Works

This example demonstrates how to automate the Shadow DOM scenario using Google Puppeteer.

Why Practice Shadow DOM on XQA?

  • Real-world scenario that mimics production applications
  • Works with Puppeteer and all other major test frameworks
  • No signup required - start practicing immediately
  • More advanced scenarios than DemoQA (like Shadow DOM in iframes)

Try with Other Frameworks