当前位置: 首页 > 面试题库 >

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

蒙才
2023-03-14
问题内容

我想通过Selenium Webdriver启动Firefox浏览器时禁用通知。我找到了这个答案,但是它已被弃用,在Firefox上对我不起作用(尽管它在Chrome上可以完美运行)。

我将这种依赖关系用于我的 pom.xml

<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-html" target="_blank">java</artifactId>
    <version>3.11.0</version>
</dependency>

问题答案:

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

  • 要在 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/”);



 类似资料:
  • 问题内容: 我想启动浏览器(FF,CHROME)以测试禁用的cookie,我尝试这样做: 但这不行… 问题答案: 我刚刚获得了Firefox的解决方案: 但我不知道如何使用Chrome进行管理。

  • 问题内容: 我在Rails项目(在Ubuntu 10.04系统上)中使用Capybaraselenium,并且现在在运行测试firefox负载时刚刚升级了firefox,但是现在它已安装了所有附加组件,并且一直等到我设置好每个人第一次。 启动selenium时是否可以禁用所有这些附加组件? 要么 有没有办法设置我所有的加载项并保存设置,以免每次运行测试时都提示我? 更新资料 如果我将其更改为使用c

  • 问题内容: 我一直在构建一个简单的应用程序来学习angular.js。到目前为止,我已经将MEAN堆栈中的所有内容连接在一起,并且能够从Mongo中保存和检索数据。 该应用程序本质上是一个待办事项列表。用户可以创建一个项目,并在项目内部创建带有“待办事项”的“卡片”,然后可以从一个州转移到另一个州(“积压”,“进行中”,“完成”等)。 我希望能够将通知推送给所有已连接的人员,以告知其应用程序需要刷

  • 我找不到任何解决这个问题的办法,这就是为什么张贴在这里。对不起,这个愚蠢的问题。 我无法使用selenium网络驱动程序启动任何浏览器。请在下面找到详细信息: 我的电脑中的Chrome版本:55.0.2883.87 m版 Chrome路径:C:\Program Files\Google\Chrome\Application\chrome.exe Chrome驱动程序版本:2.26 使用seleni

  • 问题内容: 尝试使用配置文件设置在Firefox中使用Python中的Selenium禁用Flash。这个问题指定了一种通过GUI进行操作的方法,但是对于这种特定用例,最好以编程方式进行操作。具体来说,最好的解决方案是允许在新创建的配置文件对象中禁用Flash。 非常感谢! 问题答案: 您可以使用以下配置文件禁用闪光灯。

  • 问题内容: 尝试使用配置文件设置在Firefox中使用Python中的Selenium禁用Flash。 这个问题指定了一种通过GUI进行操作的方法,但是对于这种特定用例,最好以编程方式进行操作。具体来说,最好的解决方案是允许在新创建的配置文件对象中禁用Flash。 非常感谢! 问题答案: 您可以使用以下配置文件禁用Flash。