I am automating 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 popup 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. Why is this happening and what who do I need to do to correct it?
HTML snippet:
<button _ngcontent-ng-c1987900360="" id="confirmBookingModal" type="button" variant="primary" class="btn btn-primary"> Confirm Booking </button>
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 timeout 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?