如何使用selenium为firefox浏览器禁用通知

时间:2017-05-11 07:23:16

标签: selenium-webdriver

enter image description here

我想在启动firefox浏览器时完成禁用通知

3 个答案:

答案 0 :(得分:2)

对于不同的浏览器/驱动程序,需要设置不同的配置文件/选项:

<强>火狐

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

Chrome (来源: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);

答案 1 :(得分:2)

对于Python:

options = Options()
options.set_preference('dom.webnotifications.enabled', False)

答案 2 :(得分:0)

对于最新版本的Firefox(我相信它是从版本44开始),只需将dom.webnotifications.enabled的值更改为false。默认情况下,允许弹出窗口是正确的。 代码在这里:

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

WebDriver driver = new FirefoxDriver(options);