Shadow DOM Nested

Difficult DOM Shadow Intermediate Nice to Try

Hands-on

Interactive Sandbox

Static partial

Try this

  1. Open page
  2. Interact control
  3. Read result

Assert this

  • Visible elements
  • Text matches
  • Button state toggles

Difficult DOM / Shadow nested

Shadow DOM Nested

Two layers of shadow roots hide the actionable elements.

Pierce outer and inner shadow roots to reach the targets.

Nested shadow content loads here...

Learning & behavior

User flow

  1. Open page
  2. Interact control
  3. Read result

Learning objectives

  • Pick solid locators
  • Time waits
  • Assert state

Suggested assertions

  • Visible elements
  • Text matches
  • Button state toggles

Selector tips

Good

  • [data-test-id='shadow-dom-nested-primary']
  • [data-test-id='shadow-dom-nested-secondary']
  • [data-test-id='shadow-dom-nested-action']
  • [aria-label='Shadow DOM Nested']
  • getByRole('button', { name: 'Shadow' })

Fallback

  • section.shadow-dom-nested-container :nth-of-type(1)
  • .card.shadow_dom_nested button:nth-of-type(1)
  • form.shadow-dom-nested-form .field-group:nth-child(1)

Avoid

  • .mt-4.mb-2.flex.items-center > input:nth-child(1)
  • .css-1a2b3c4
  • div[class*='temp-'][class*='hover']

Notes

  • Some parts delay render
  • Icon buttons need aria-label
  • Layout classes may shift