Home > database >  How to handle alert using Selenium python&
How to handle alert using Selenium python&

Time:01-31

When browser redirect me to telegram page, i have an alert(look at the screenshot). How can I cancel It?

I use this code, but i have an error at the second line:

alert = Alert(driver)
alert.dismiss()

Error: enter image description here

Screenshot of alert, which i try to close: enter image description here

CodePudding user response:

Please try this

driver.switch_to.alert.accept()

This should work

CodePudding user response:

You need to switch the focus to the alert box before accessing it.

Try this

WebDriverWait(driver, 10).until(EC.alert_is_present())
alert_box = driver.switch_to.alert
alert_box.dismiss()

CodePudding user response:

Can you try this:

driver.switch_to.alert.dismiss()
  • Related