How to Click the "OK" Button within an Alert using Python + Selenium How to Click the "OK" Button within an Alert using Python + Selenium selenium selenium

How to Click the "OK" Button within an Alert using Python + Selenium


To click on the OK button within the you need to induce WebDriverWait for the desired alert_is_present() and you can use the following solution:

WebDriverWait(driver, 10).until(EC.alert_is_present())driver.switch_to.alert.accept()

Note : You have to add the following imports :

from selenium.webdriver.support.ui import WebDriverWaitfrom selenium.webdriver.support import expected_conditions as EC

Reference

You can find a couple of relevant discussions in: