skip to Main Content

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

2

Answers


  1. Chosen as BEST ANSWER

    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);
    

  2. It seems Brower Notification to me not an alert.
    Try with chrome options to disabled the Brower Notification

    Here are two ways to disabled the browser notifications.

    from selenium.webdriver.chrome.service import Service
    from webdriver_manager.chrome import ChromeDriverManager
    
    chrome_options = webdriver.ChromeOptions()
    prefs = {"profile.default_content_setting_values.notifications" : 2}
    chrome_options.add_experimental_option("prefs",prefs)
    
    driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()),options=chrome_options)
    driver.get("specific url")
    

    or

    from selenium.webdriver.chrome.service import Service
    from webdriver_manager.chrome import ChromeDriverManager
    
    chrome_options = webdriver.ChromeOptions()
    chrome_options.add_argument("--disable-notifications")
    
    driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()),options=chrome_options)
    driver.get("specific url") 
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search