[Python] can i click a button with selenium without waiting the webpage to fully load

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

  1. Stack

    Stack Membro Participativo

    im trying to open a webpage and click a button as soon as it sees it without waiting for the webpage to fully loads

    from selenium.webdriver.chrome.service import Serviceenter code here
    from webdriver_manager.chrome import ChromeDriverManager
    from selenium.webdriver.common.by import By

    def open_webpage():
    service = Service(ChromeDriverManager().install())
    driver = webdriver.Chrome(service=service)
    driver.get("website_url")

    try:
    button = driver.find_element(By.XPATH, '//button[@type="submit" and @data-umami-event="download"]')

    if button.is_displayed():
    button.click()
    print("Button clicked")
    else:
    print("Button is not visible.")

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    WebDriverWait(driver, 10).until(
    EC.presence_of_all_elements_located((By.TAG_NAME, 'a'))
    ) ```

    Continue reading...

Compartilhe esta Página