To select an element from a nested shadow root, you can use the querySelector().shadowRoot
method in order to access each shadow root level:
// Assuming you have the parent element that contains the shadow root
const parentElement = document.querySelector('#start');
// Access the first shadow root
const firstShadowRoot = parentElement.shadowRoot;
// Access the second shadow root
const secondShadowRoot = firstShadowRoot.querySelector('plural').shadowRoot;
// Access the third shadow root
const thirdShadowRoot = secondShadowRoot.querySelector('main').shadowRoot;
// Get the paragraph inside the third shadow root
const p = thirdShadowRoot.querySelector('p');
console.log(p.textContent);
Please note: you cannot skip a shadow DOM level, so make sure you follow each one of them from the top of the DOM.
Another tip that might help:
When handling a complex DOM which envolved many nested Shadow DOMs the
best way to find your element path is using the devtools: right click on the element > Copy > Copy js path
(example for Chrome)