【发布时间】:2021-11-06 18:59:34
【问题描述】:
我浏览了许多帖子,但没有一个可以帮助我让它发挥作用。
我想使用 selenium 和 Java 程序安装我的 firefox 插件,即在启动 firefox 时安装插件。
注意:如果我使用设置中的选项“从文件安装插件..”选项手动将插件(*.xpi 文件)安装到 Firefox 浏览器,它会正确安装。
Java 代码:
System.setProperty("webdriver.gecko.driver", "geckodriver-v0.24.0-win64\\geckodriver.exe");
FirefoxOptions firefoxOptions = new FirefoxOptions();
FirefoxProfile profile = new FirefoxProfile();
profile.addExtension(new File("my_webext.xpi"));
firefoxOptions.setProfile(profile);
WebDriver firefoxDriver = new FirefoxDriver(firefoxOptions);
firefoxDriver.get("http://www.google.com");
Selenium 依赖版本:(4.0.0-rc-1/4.0.0-alpha-2/3.141.59)
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.0.0-alpha-2</version>
</dependency>
Gecko 驱动程序版本:0.24.0 或 0.29.1
Firefox 版本:92.0(64 位)
IDE:STS
操作系统:Windows 10
-
当我运行上面的代码时,火狐浏览器打开了,但是插件没有安装。
-
我在控制台上看到以下消息:
1631259829322 mozrunner::runner INFO Running command: "C:\\Program Files\\Mozilla Firefox\\firefox.exe" "-marionette" "-foreground" "-no-remote" "-profile" "C:\\Users\\ab\\AppData\\Local\\Temp\\rust_mozprofile.CSQe58I2OCxk"
1631259830585 Marionette INFO Marionette enabled
JavaScript error: resource://gre/modules/XULStore.jsm, line 66: Error: Can't find profile directory.
console.warn: SearchSettings: "get: No settings file exists, new profile?" (new NotFoundError("Could not open the file at C:\\Users\\ab\\AppData\\Local\\Temp\\rust_mozprofile.CSQe58I2OCxk\\search.json.mozlz4", (void 0)))
1631259834207 Marionette INFO Listening on port 59932
1631259834612 RemoteAgent WARN TLS certificate errors will be ignored for this session
Sep 10, 2021 1:13:54 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
【问题讨论】:
标签: java selenium selenium-webdriver firefox firefox-addon