enter image description here

As for the image, I need to capture an element which is under show user agent shadow DOM.

I tried using //*[@id="placeholder"], but as for the image, its Zero matches. By looking at some other older post at this website I tried using

WebElement ele = (WebElement) ((JavascriptExecutor)driver).executeScript("return arguments[0].shadowRoot", element);

for that also, I'm not getting the element. So Is there any other way to capture the element below the show user agent shadow DOM.

1 Answer 1


The JavaScript code you provided is almost accurate; however, some modification is needed to effectively capture an element within the Shadow DOM.

Firstly, obtain the JavaScript path of the intended element for locating using, copy jS path.

enter image description here

Subsequently, paste the path into the console and press Enter, ensuring the precise selection of the correct element .

enter image description here

Next, go ahead and use the provided JavaScript in your code. Simply paste the jS path into the specified JavaScript context.

JavascriptExecutor js = (JavascriptExecutor) driver;
WebElement download = (WebElement) js.executeScript("return Paste the jS path after return");

If you intend to trigger a click event on the element, consider utilizing the following JavaScript code:

((JavascriptExecutor) driver).executeScript("arguments[0].click();", download);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.