how can i remove notifications and alerts from browser? selenium python 2.7.7 how can i remove notifications and alerts from browser? selenium python 2.7.7 selenium selenium

how can i remove notifications and alerts from browser? selenium python 2.7.7


You can disable the browser notifications, using chrome options. Sample code below:

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)


With the latest version of Firefox the above preferences didn't work.

Below is the solution which disable notifications using Firefox object

_browser_profile = webdriver.FirefoxProfile()_browser_profile.set_preference("dom.webnotifications.enabled", False)webdriver.Firefox(firefox_profile=_browser_profile)

Disable notifications when using Remote Object:webdriver.Remote(desired_capabilities=_desired_caps, command_executor=_url, options=_custom_options, browser_profile=_browser_profile)

selenium==3.11.0


Usually with browser settings like this, any changes you make are going to get throws away the next time Selenium starts up a new browser instance.

Are you using a dedicated Firefox profile to run your selenium tests? If so, in that Firefox profile, set this setting to what you want and then close the browser. That should properly save it for its next use. You will need to tell Selenium to use this profile though, thats done by SetCapabilities when you start the driver session.