Java 未能等待扩展背景页加载chrome扩展。Can';不要禁用扩展
我在chromedriver的selenium测试中使用了一个扩展,但有时我需要禁用(或删除)chrome选项中的扩展,并在没有任何扩展的情况下启动chromedriver 因此,我尝试实现以下实验逻辑,其中我创建了一个扩展并立即禁用它:Java 未能等待扩展背景页加载chrome扩展。Can';不要禁用扩展,java,selenium,selenium-chromedriver,Java,Selenium,Selenium Chromedriver,我在chromedriver的selenium测试中使用了一个扩展,但有时我需要禁用(或删除)chrome选项中的扩展,并在没有任何扩展的情况下启动chromedriver 因此,我尝试实现以下实验逻辑,其中我创建了一个扩展并立即禁用它: @BeforeSuite(alwaysRun = true) public void initCapabilities() { getOptions().addExtensions("path/to/file"
@BeforeSuite(alwaysRun = true)
public void initCapabilities() {
getOptions().addExtensions("path/to/file");
//getOptions().addArguments("--disable-extensions");//1
System.setProperty("webdriver.chrome.driver", "path/to/driver");
new ChromeDriver(getOptions());
}
...................
private ChromeOptions options = new ChromeOptions();
protected ChromeOptions getOptions() {
return options;
}
所有这些都可以正常工作,但当我添加第(1)行时,浏览器将在不扩展的情况下启动,项目立即失败:
> org.openqa.selenium.WebDriverException: unknown error: failed to wait
> for extension background page to load:
> chrome-extension://lkpgdponleanlidigfljoenpapabebon/background.html
> from unknown error: page could not be found:
> chrome-extension://lkpgdponleanlidigfljoenpapabebon/background.html
> Build info: version: '3.141.59', revision: 'e82be7d358', time:
> '2018-11-14T08:17:03'
此外,我还尝试使用其他方法禁用扩展,但所有这些方法都无效-浏览器以扩展打开:
getOptions().setExperimentalOption("useAutomationExtension", false);
getOptions().setCapability("chrome.switches", new String[]{"--disable-extensions"});
getOptions().setCapability("chrome.switches", "--disable-extensions");
如何从chromeoptions中正确禁用/删除扩展?
可能存在其他方式吗