Search code examples
pythonpython-3.xseleniumselenium-webdriverselenium-chromedriver

Handle notifications in Python + Selenium Chrome WebDriver


How can Selenium Chrome WebDriver notifications be handled in Python?

Have tried to dismiss/accept alert and active element but seems notifications have to be treated other way. Also, all the Google search results are driving me to Java solution which I do not really need. I'm a newbie in Python.

Thanks in advance.

enter image description here


Solution

  • You can disable the browser notifications, using chrome options.

    chrome_options = webdriver.ChromeOptions()
    prefs = {"profile.default_content_setting_values.notifications" : 2}
    chrome_options.add_experimental_option("prefs",prefs)
    driver = webdriver.Chrome(chrome_options=chrome_options)