Skip to content Skip to sidebar Skip to footer

How To Click The "ok" Button Within An Alert Using Python + Selenium

I want to click the 'OK' button in this pop up dialog I tried: driver.switchTo().alert().accept(); but it doesn't work

Solution 1:

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.uiimportWebDriverWaitfrom selenium.webdriver.supportimport expected_conditions asEC

Reference

You can find a couple of relevant discussions in:

Post a Comment for "How To Click The "ok" Button Within An Alert Using Python + Selenium"