Selenium网格:在会话上安装chrome扩展

2024-06-07 21:14:26 发布

您现在位置:Python中文网/ 问答频道 /正文

在chrome浏览器的Selenium网格测试中,我需要使用chrome Store中的一个chrome扩展,但是我有一些问题:(

  1. 我试图转到浏览器(https://chrome.google.com/webstore/detail/..)中的扩展URL并按Install键,但无法在弹出的浏览器窗口中确认安装
  2. 我试图下载crx扩展文件,但我打开它在浏览器中看到确认窗口,不知道如何确认安装
  3. 我尝试使用这个方法-https://developer.chrome.com/extensions/external_extensions添加JSON文件并运行browser-don-work,但我在Mac上尝试过,而不是在Linux上
  4. 在webdriver.remote只能使用FireFox选项(seleniumhq.github.io/selenium/docs/api/py/webdriver_remote/selenium.webdriver.remote.webdriver.html)

如果我使用Selenium Grid,我无法更改Chrome浏览器的开始设置,也无法添加任何键:(

也许你知道在Selenium网格浏览器会话上安装扩展的另一种方法?在


Tags: 文件方法storehttpscom网格remoteselenium
1条回答
网友
1楼 · 发布于 2024-06-07 21:14:26

您可以使用ChromeOptions。在

ChromeOptions options = new ChromeOptions();
options.addExtensions(new File("/path/to/extension.crx"));
ChromeDriver driver = new ChromeDriver(options);

或者,您可以将这些选项添加到已经存在的DesiredCapabilities对象中。在

^{pr2}$

您还可以使用远程web驱动程序:

DesiredCapabilities capability = DesiredCapabilities.chrome();
// above code goes here...
WebDriver driver = new RemoteWebDriver(new URL(hubUrl), capability);

相关问题 更多 >

    热门问题