[Python] Modal Popup - Selenium/Python

Discussão em 'Python' iniciado por Stack, Setembro 3, 2025.

  1. Stack

    Stack Membro Participativo

    I am attempting to automate a confirmation request, and my code gets me all the way to the end, but when it comes to actually confirming my reservation, there is a pop up modal window that appears as a layover on the original webpage. The button that's clickable is called, Confirm Booking but when i call that, it doesn't click. my code ends up timing out. Can someone please help with why this is happening and what i need to do to correct it?

    HTML Snippet:

    Confirm Booking

    My Code:

    # Wait for the modal to appear and find the confirm button
    confirm_button = WebDriverWait(driver, 5).until(
    EC.element_to_be_clickable((By.XPATH, "//button[contains(@class, 'btn-primary') and text()='Confirm']"))
    )
    confirm_button.click()


    except TimeoutException: print("Modal or Confirm button not found. Please check the element ID or visibility.")

    finally: # Close the browser time.sleep(2) # Optional: wait to see the effect driver.quit()

    I keep receiving a time out error or my system will print the Modal or Confirm button not found. Please check the element ID or visibility. - How do i fix this?

    Continue reading...

Compartilhe esta Página