【发布时间】:2021-02-02 08:51:01
【问题描述】:
我需要使用 Selenium 来启动 Edge (Chromium) 浏览器。我可以毫无问题地做到这一点。
但是,我想在安装了解压扩展程序的情况下启动上述浏览器。我有扩展的路径。通过在我的ChromeOptions 中添加一个名为--load-extentsion=<path> 的参数,我可以在Chrome 中做到这一点。但是,这对 Edge Chromium 不起作用。
并使用下面的代码:
EdgeOptions edgeOptions = new EdgeOptions();
File extension = new File(extensionPath + File.separator + "my-extension.crx");
byte[] fileContent;
WebDriver webDriver;
try {
fileContent = Files.readAllBytes(extension.toPath());
edgeOptions.setCapability("extensions",Base64.getEncoder().encodeToString(fileContent));
webDriver = new EdgeDriver(edgeOptions);
} catch (IOException e) {
e.printStackTrace();
}
浏览器启动正常,但我的扩展程序没有加载。
我需要能够加载解压的扩展程序,而不必将其发布到 Chrome 或 Edge 应用商店。
谁能帮帮我?
谢谢 斯里拉姆
【问题讨论】:
-
如果你已经有了 .crx,你不能在 EdgeOptions 中使用 .addExtensions() 吗?然后你只需要传递文件对象。
标签: java selenium-webdriver microsoft-edge-chromium