Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How click on a button under a CLOSED shadow DOM with selenium for python?

I'm looking to access to the button but the CLOSED shadow DOM block me, how can i switch it to open and have access to this button ?

<div class="button-holder help-button-holder">
  #shadow-root (closed)
    <link rel="stylesheet" href="chrome-extension://mpbjkejclgfgadiemmefgebjfooflfhl/src/solve/solver-button.css">
    <button tabindex="0" title="Solve the challenge" id="solver-button"></button>
</div>
like image 220
Yvann Ponce Avatar asked Jan 01 '26 11:01

Yvann Ponce


1 Answers

I have encounter the same problem and manager to work around it.

So the idea is to focus on the closest element before "shadow-root (closed)", then use Tab key to reach that solver button, then click it.

I work on Kotlin, but you should be able to attempt for python.

// click to focus on the solver button wrapper
driver.findElement(By.cssSelector(".button-holder.help-button-holder")).click()

// use Actions instead of pointing to the solver button itself
val actions = Actions(driver)
actions.sendKeys(Keys.TAB)
actions.click()
like image 198
piusyikyu Avatar answered Jan 03 '26 01:01

piusyikyu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!