4

enter image description here

I want to complete disable the notification when i launch a firefox browser

Suncatcher
  • 10,355
  • 10
  • 52
  • 90
  • Possible duplicate of [Disable Chrome notifications (Selenium)](http://stackoverflow.com/questions/34343423/disable-chrome-notifications-selenium) – NarendraR May 11 '17 at 08:38

3 Answers3

6

For different browsers/drivers there are different profiles/options that need to be set:

Firefox

FirefoxProfile ffprofile = new FirefoxProfile();
ffprofile.setPreference("dom.webnotifications.enabled", false);
WebDriver driver = new FirefoxDriver(ffprofile);

Chrome (Source: https://stackoverflow.com/a/34368704/904375)

Map prefs = new HashMap();
prefs.put("profile.default_content_setting_values.notifications", 2);
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", prefs);
WebDriver driver = new ChromeDriver(options);
Community
  • 1
  • 1
Zeeshan S.
  • 2,041
  • 2
  • 21
  • 40
  • 1
    FirefoxProfile is deprecated – Sodium Feb 09 '18 at 11:11
  • Since FirefoxProfile got deprecated, we can use FirefoxOptions in the below way ------ FirefoxOptions firefoxOptions = new FirefoxOptions(); firefoxOptions.addPreference("dom.webnotifications.enabled",false); webdriver = new FirefoxDriver(firefoxOptions); – Binnu Jesudasan Gudapati Nov 07 '18 at 02:27
2

For the latest versions of Firefox (I believe its from version 44), just change the value of dom.webnotifications.enabled to false. By default, it's true which allows pop-up. Code here:

FirefoxOptions options = new FirefoxOptions();
options.setProfile(new FirefoxProfile());
options.addPreference("dom.webnotifications.enabled", false);

WebDriver driver = new FirefoxDriver(options);
Dhruv
  • 21
  • 3
2

For Python:

options = Options()
options.set_preference('dom.webnotifications.enabled', False)
crappy_hacker
  • 191
  • 3
  • 6
  • Running this as options = Options is confusing thins. make sure to use options=Options(). Don't forget the paranthesis – PouJa Sep 19 '21 at 03:10