[Python] How can i handle the shadow-root (open) with selenium

Discussão em 'Python' iniciado por Stack, Dezembro 1, 2024.

  1. Stack

    Stack Membro Participativo

    Im working scrapping wallapop making a Second-hand cars listing. But Wallapop has a limit of 26 items. If you click "Ver más productos" (See more products) You can see more products on the website[​IMG]

    Im trying to find the button with this code in python:

    while True:
    try:
    shadow_host = driver.find_element(By.CSS_SELECTOR, "walla-button")
    shadow_root = driver.execute_script('return arguments[0].shadowRoot', shadow_host)
    skip_tutorial_button = shadow_root.find_element(By.CSS_SELECTOR, "button.walla-button__button.walla-button__button--medium.walla-button__button--tertiary.walla-button__button--neutral")
    skip_tutorial_button.click()
    except Exception as e:
    print("No se encontró el botón 'Ver más productos' o ya se han cargado todos los productos.")
    break


    Thats is the URL: https://es.wallapop.com/app/search?...&latitude=40.41956&order_by=price_high_to_low

    Continue reading...

Compartilhe esta Página