How to get past a cookie agreement page using Python and Selenium?

The element Alles akzeptieren is within #shadow-root (open).

Alles


Solution

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

  • Code Block:

    driver.get("https://www.heise.de/download/")
    time.sleep(5)
    element = driver.execute_script("""return document.querySelector('#usercentrics-root').shadowRoot.querySelector('footer div div div button[data-testid="uc-accept-all-button"]')""")
    element.click()
    
  • Browser Snapshot:

heise


References

You can find a couple of relevant discussions in:

Leave a Comment