Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am tying to access this element inside of shadow-root (closed)

I have tried to do:

driver.findElement(By.xpath("//*[@id="solver-button"]")).click();

but it cant locate the element because of shadow root.

So I am searching for a method to go inside of shadow root to locate "solver-button".

question from:https://stackoverflow.com/questions/65846986/access-element-inside-shadow-root-in-selenium-with-java

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
305 views
Welcome To Ask or Share your Answers For Others

1 Answer

shadowbutton=driver.execute_script(
    "return document.querySelector('div[class="button-holder help-button-holder"]').shadowRoot.querySelector('button[id="solver-button"]')")

shadowbutton.click()

shadowRoot is not part of dom so you have to first find the root element that has the shadow root and then call it using 'shadowRoot' and then call the target element from it


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...