如何使用硒在Java的firefox驱动程序中添加扩展名

时间:2019-08-21 20:25:01

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

如何在Java的硒中的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。

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

所以请指导我该怎么做。

1 个答案:

答案 0 :(得分: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);