【问题标题】:How to add extension in firefox driver in Java using selenium如何使用 selenium 在 Java 中的 firefox 驱动程序中添加扩展
【发布时间】:2019-12-27 03:41:39
【问题描述】:

如何在 Java 中的 selenium 中的 firefox 驱动程序中添加扩展

尝试了以下可能性。

第一次尝试的解决方案

FirefoxOptions firefoxOptions = new FirefoxOptions();
FirefoxProfile profile = new FirefoxProfile();
profile.addExtension(new File("/usr/local/bin/foxyproxy_standard-6.6.2-an+fx.xpi"));
profile.setPreference("extensions.firebug.currentVersion", "1.8.1");
firefoxOptions.setProfile(profile);
WebDriver firefoxDriver = new FirefoxDriver(firefoxOptions);

它没有给出任何错误,但它在没有任何扩展的情况下启动。

使用依赖

    <dependency>
      <groupId>org.seleniumhq.selenium</groupId>
      <artifactId>selenium-java</artifactId>
      <version>3.12.0</version>
    </dependency>
    <dependency>
      <groupId>io.github.bonigarcia</groupId>
      <artifactId>webdrivermanager</artifactId>
      <version>3.2.0</version>
    </dependency>

第二次尝试的解决方案

FirefoxProfile profile = new FirefoxProfile();
profile.addExtension(new File("/usr/local/bin/foxyproxy_standard-6.6.2-an+fx.xpi"));
profile.setPreference("extensions.firebug.currentVersion", "1.8.1");
WebDriver firefoxDriver = new FirefoxDriver(profile);

它也没有给出任何错误,但它在没有任何扩展的情况下启动。

使用依赖

    <dependency>
      <groupId>org.seleniumhq.selenium</groupId>
      <artifactId>selenium-java</artifactId>
      <version>3.0.0-beta4</version>
    </dependency>
    <dependency>
      <groupId>io.github.bonigarcia</groupId>
      <artifactId>webdrivermanager</artifactId>
      <version>3.2.0</version>
    </dependency>

第三次尝试的解决方案

从 Firefox 手动创建配置文件。 1.打开默认firefox 2.关于:prfiles 3. 创建新配置文件为“TestProfile” 4.在新浏览器中启动配置文件 5.添加一些附加组件 6.关闭浏览器 7.然后执行下面的代码。

    ProfilesIni profilesIni = new ProfilesIni();
    FirefoxOptions firefoxOptions = new FirefoxOptions();
    FirefoxProfile profile = profilesIni.getProfile("TestProfile");
    firefoxOptions.setProfile(profile);
    WebDriver firefoxDriver = new FirefoxDriver(firefoxOptions);

这也不行

我已经尝试使用 chrome 驱动程序,它也可以正常工作,但 chromedriver 在无头模式下没有扩展支持,因此需要使用 firefox webdriver。

我已经尝试了所有解决方案,但没有一个有效

所以请指导我该怎么做。

【问题讨论】:

  • 你能用你所有的代码试验和相关错误更新问题吗?
  • 我已经添加了所有解决方案现在可以查看一次@DebanjanB
  • 试用 FF68、selenium-java 4.0.0-alpha-2 和 v0.24.0 。在 windows 机器上试用。扩展正确加载,没有任何问题。 ` FirefoxProfile 配置文件 = 新的 FirefoxProfile(); profile.addExtension(new File("foxyproxy_basic-5.5-an+fx.xpi")); options.setProfile(profile); `
  • 谢谢@RahulL 这对我有用。

标签: selenium selenium-webdriver firefox-addon firefox-headless


【解决方案1】:

尝试使用 FF68、selenium-java 4.0.0-alpha-2 和 v0.24.0 。在 Windows 机器上测试。

FirefoxProfile profile = new FirefoxProfile();

profile.addExtension(new File("foxyproxy_basic-5.5-an+fx.xpi"));

options.setProfile(profile);

【讨论】:

  • 这仅适用于 4.0.0 alpha 版本?我正在为 3.141.59 尝试它,但它不起作用
  • 已使用 Selenium-java 3.141.59 、geckodriver 0.26.0 (e9783a644016 2019-10-10 13:38 +0000) + FF72 检查。它工作正常。
  • 呃,真的吗?,我真的无法添加扩展名。它的代码完全相同。
  • 您能否添加有关如何创建驱动程序的更多信息?我的意思是整个代码,如果可能的话
  • 我做到了,问题是当您尝试安装自己的扩展程序时,如果您忘记添加应用程序和最低浏览器版本标签,它将无法正常工作...
猜你喜欢
  • 2021-11-06
  • 1970-01-01
  • 2018-10-30
  • 2016-06-21
  • 2022-01-07
  • 2018-10-25
  • 2013-04-25
  • 1970-01-01
  • 2017-01-27
相关资源
最近更新 更多