I am trying to use playwright to assert text like below which is inside open shadow root which has no tags associated to that specific text. These texts are inside table cells.
<div>
<table-cell>
#shadow-root (open)
"Text content"
</table-cell>
I am trying to assert "Text content" which is under shadow DOM. I was able to uniquely locate but can not get the text inside it. It always return an empty string or object depends on the method I tried to retrieve the text. Example typescript code I tried is below,
const text = this.page.locator('table-cell').innerText();
I was able to get other texts which are inside shadow root which has a tag associated with that text. But in this case this specific text line don't have any tag associated to that so the methods aren't working as for other scenarios.
How do I get the contents of #shadow-root if it only contains the text, without any tags ?
innerTextis a property onHTMLElementA shadowRoot is not a
HTMLElementand does not have aninnerTextproperty.It does have a
innerHTMLproperty: https://developer.mozilla.org/en-US/docs/Web/API/ShadowRootlet text = document.querySelector("your-element").shadowRoot.innerHTMLGets you the text