相关文章推荐
严肃的双杠  ·  antd ...·  1 周前    · 
气宇轩昂的香瓜  ·  Python ...·  5 天前    · 
善良的番茄  ·  Python ...·  5 天前    · 
酒量大的洋葱  ·  python windows ...·  3 周前    · 
刚失恋的鸵鸟  ·  使用 ASP.NET AJAX | ...·  8 月前    · 
耍酷的大象  ·  用 Numba 加速 Python ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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>

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()
def expand_shadow_element(element):
  shadow_root = driver.execute_script('return arguments[0].shadowRoot', element)
  return shadow_root
outer = expand_shadow_element(driver.find_element_by_css_selector(".button-holder.help-button-holder"))
inner = outer.find_element_by_xpath(".//button[@id='solver-button']")
inner.click()

You can do the following to click the element inside the shadow root.

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.