使用addExtensions选项时,Selenium不会在Firefox中安装附加组件 [英] Selenium does not install add-on in Firefox when using the addExtensions option

查看:60
本文介绍了使用addExtensions选项时,Selenium不会在Firefox中安装附加组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在TypeScript和Jest上下文中使用 selenium geckodriver 运行它时,我想在Firefox中安装自定义XPI文件.

I want to install a custom XPI file in Firefox when running it with selenium and geckodriver in a TypeScript and Jest context.

测试脚本的重要部分这是:

let driver: webdriver.WebDriver;
const firefoxExt = path.resolve(__dirname, '..', '..', 'extension', 'firefox.xpi');
const firefoxOptions = new firefox.Options().addExtensions(firefoxExt);
driver = new webdriver.Builder().forBrowser('firefox').setFirefoxOptions(firefoxOptions).build();

我希望Firefox作为附加组件启动并安装firefox.xpi,但是打开的Firefox实例中没有附加组件.XPI本身没有问题,因为XPI可以作为临时扩展手动安装,没有问题.另外,XPI存在于路径中,否则会在 path.resolve 上出错.

I am expecting Firefox to launch and install firefox.xpi as an add-on, but there are no add-ons present in the opened Firefox instance. There is no issue with the XPI itself, as the XPI can be installed manually, as a temporary extension, without issues. Also, the XPI exists at the path, as otherwise it would error out on path.resolve.

为了让其他人重现该问题,我创建了一个带有最小限度,可复制示例的存储库.看到这个仓库: https://github.com/slhck/web-extension-selenium-测试

For others to reproduce the issue, I have created a repository with a minimal, reproducible example. See this repo: https://github.com/slhck/web-extension-selenium-test

请注意,这不是以下项的重复项:

Note that this is not a duplicate of:

  • Cannot load extension using firefox driver selenium when using AddExtension (unanswered, closed)
  • How to install extension permanently in geckodriver (I do not want a permanent install, as the XPI will be changed before the test suite runs)
  • How to load extension within chrome driver in selenium with python (I am already using addExtension)

我已经在Selenium本身中创建了错误报告,但尚未收到任何活动.

I have created a bug report in Selenium itself, but it has not received any activity yet.

有人知道这个问题可能是什么,如何解决?

Does anyone know what the issue could be, and how it could be solved?

推荐答案

您可以使用 installAddon .可能有一种更优雅的方法来执行此操作,但是下面的代码有效:

You can use installAddon. There may be a more elegant way to do this, but the code below works:

beforeAll(async () => {
  const firefoxExt = path.resolve(__dirname, '..', '..', 'extension', 'firefox.xpi');
  driver = new webdriver.Builder().forBrowser('firefox').build();
  new firefox.Driver(driver.getSession(), driver.getExecutor()).installAddon(firefoxExt, true);
});

这篇关于使用addExtensions选项时,Selenium不会在Firefox中安装附加组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆