[Python] Selenium: Unable to Click Button Inside Shadow Root

Discussão em 'Python' iniciado por Stack, Fevereiro 17, 2025.

  1. Stack

    Stack Membro Participativo

    I’m trying to accept the cookies on a website, but the pop-up window doesn’t load properly.

    Does anyone know how to resolve this?

    Website URL: https://www.guest.wemolo.at/?access...9.dyAdGEDJ87U-i_lBytN3Y-_kIuJnRKvJKJgVOQ0MlfE

    from selenium import webdriver
    from selenium.webdriver.support.wait import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC

    driver = webdriver.Firefox()
    driver.maximize_window()
    url = 'https://www.guest.wemolo.at/?access_token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6IjQ4NWIyZWEyLTY2MTItNDU3ZS05YTA4LTRhODBjMTgxNzM4MiJ9.dyAdGEDJ87U-i_lBytN3Y-_kIuJnRKvJKJgVOQ0MlfE'
    driver.get(url)

    wait = WebDriverWait(driver, 10)
    shadow_host = wait.until(EC.presence_of_element_located((By.XPATH, "//button[contains(text(), 'Alles Akzeptieren')]")))
    shadow_root = shadow_host.shadow_root
    load = shadow_root.find_element(By.XPATH, "//button[contains(text(), 'Alles Akzeptieren')]")
    load.click()


    I attempted to print the entire webpage, but the cookie consent pop-up doesn’t appear in the print output.

    After inspecting the page, I discovered that the pop-up is inside a shadow root. However, I’m unable to access it.

    Continue reading...

Compartilhe esta Página