0

1

I'm trying to click on this element with selenium but it cant find since its with in a shadow-root. It's an extension button that does something when you click it. the shadow root is closed

here is my code

root = driver.execute_script("return arguments[0].shadowRoot",driver.find_element(By.XPATH, '//div[@class="button-holder help-button-holder"]'))
    # Locate the extension button within the shadow root
    wait = WebDriverWait(driver, 10)
    button = wait.until(EC.presence_of_element_located((By.ID, "solver-button")))
    button = root.find_element(By.XPATH,"//*[@tabindex='0'][@title='Solve the challenge'][@id='solver-button']")
    button.click()```
vimuth
  • 5,064
  • 33
  • 79
  • 116
ytubk
  • 1
  • 1

1 Answers1

0

You can't invoke click on an element within shadow-root(closed) using Selenium as @hayatoito (creator of Shadow DOM) in his comment clearly mentioned:

The original motivation of introducing a closed shadow tree is "Never allow an access to a node in a closed shadow tree, via any APIs, from outside", AFAIK. Like that we can not access a node in the internal hidden shadow tree which is used in <video> element, in Blink.

In fact, I designed a closed shadow tree in such a way. If there is a way to access a node in a closed shadow tree, it should be considered as a bug of the spec.

I think it's totally okay to have an API to allow an access in the layer of Chrome apps or extensions. However, for a normal web app, I think the current agreement is "Never allow it".

If we allowed it, that means we do not need a closed shadow tree. Just having an open shadow tree is enough, I think.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352