Search code examples
pythonseleniumselenium-webdriverselenium-chromedriveralert

How to handle alert using Selenium python&


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


Solution

  • IDK which type this window has. But the easiest solution is just send "enter" to browser and window will be closed.

    import org.openqa.selenium.Keys
    
    WebElement.sendKeys(Keys.RETURN);