Blog
Shadow dom
Shadow dom
Copy JS path
Open the inspector (F12), right-click on the element and select "copy JS path" option.
Use the driver.executeScript() method to do the task.
String shadowElement = "return document.querySelector(\"#demo1\").shadowRoot.querySelector(\"p:nth-child(2)\").textContent";
String text = driver.executeScript(shadowElement).toString();
- if return is not used you'll end up with null exception
- toString() to convert the JS object to String
textContent - to get the text in the element
click() - to click on the element
Source
Source