How to handle the popup “Accepting all cookies” when the element is data-testid – Using Selenium in Python

The element Accept All is within #shadow-root (open).

kostal


Solution

To click on Accept All you have to use shadowRoot.querySelector() and you can use the following Locator Strategy:

  • Code Block:

    driver.get("https://www.kostal-solar-portal.com/#/")
    time.sleep(5)
    element = driver.execute_script("""return document.querySelector('#usercentrics-root').shadowRoot.querySelector("button[data-testid='uc-accept-all-button']")""")
    element.click()
    

References

You can find a couple of relevant discussions in:

Leave a Comment