how to disabling notification using selenium for firefox browser

后端 未结 3 578
后悔当初
后悔当初 2021-01-03 03:33

\"enter

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

相关标签:
3条回答
  • 2021-01-03 04:10

    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);
    
    0 讨论(0)
  • 2021-01-03 04:11

    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);
    
    0 讨论(0)
  • 2021-01-03 04:15

    For Python:

    options = Options()
    options.set_preference('dom.webnotifications.enabled', False)
    
    0 讨论(0)
提交回复
热议问题