栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何使用Selenium针对Firefox和Chrome禁用推送通知?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何使用Selenium针对Firefox和Chrome禁用推送通知?

如果您的用 是禁用 通知,则可以使用 以下选项:

  • 要在 Firefox* 浏览器客户端中禁用 推送通知 ,请使用 FirefoxProfile 并将 密钥 dom.webnotifications.enableddom.push.enabled 以及所需的 传递为 false *__****
    System.setProperty("webdriver.gecko.driver", "C:\path\to\geckodriver.exe");

    ProfilesIni profile = new ProfilesIni();
    FirefoxProfile testprofile = profile.getProfile(“debanjan”);
    testprofile.setPreference(“dom.webnotifications.enabled”, false);
    testprofile.setPreference(“dom.push.enabled”, false);
    DesiredCapabilities dc = DesiredCapabilities.firefox();
    dc.setCapability(FirefoxDriver.PROFILE, testprofile);
    FirefoxOptions opt = new FirefoxOptions();
    opt.merge(dc);
    WebDriver driver = new FirefoxDriver(opt);
    driver.get("https://www.ndtv.com/”);


注意 :此方法使用存储在我的本地系统中的现有

FirefoxProfile
名称为 debanjan 的现有文件,该文件是
根据在Windows

创建新的Firefox配置
文件中的文档
创建的

  • 要在 Chrome* 浏览器客户端中禁用 通知 ,请借助 setExperimentalOption() 来传递一个 HashMap ,该 HashMap 包含 profile.default_content_setting_values.notifications ,其 Value2 __ *
    System.setProperty("webdriver.chrome.driver", "C:\path\to\chromedriver.exe");

    Map prefs = new HashMap();
    prefs.put(“profile.default_content_setting_values.notifications”, 2);
    prefs.put(“credentials_enable_service”, false);
    prefs.put(“profile.password_manager_enabled”, false);
    ChromeOptions options = new ChromeOptions();
    options.setExperimentalOption(“prefs”, prefs);
    options.addArguments(“start-maximized”);
    options.addArguments(“disable-infobars”);
    options.addArguments(“–disable-extensions”);
    options.addArguments(“–disable-notifications”);
    WebDriver driver = new ChromeDriver(options);
    driver.get("https://www.ndtv.com/”);



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/386016.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号