我遇到了无法打开任何扩展程序的Chrome的问题。我已经添加了扩展,但是不知道如何使用Selenide框架正确运行它。你能帮我吗
@BeforeClass
public static void setUp() {
Configuration.browser = "chrome";
System.setProperty("selenide.browser", "chrome");
ChromeOptions options = new ChromeOptions();
options.addExtensions(new File("src/main/resources/uBlock Origin.crx"));
}
答案 0 :(得分:2)
硒化物:http://selenide.org/2018/01/12/selenide-4.10/
您可以在“配置”中设置自定义功能,Selenide将在打开浏览器时使用它们:
Configuration.browserCapabilities = new DesiredCapabilities();
Configuration.browserCapabilities.setCapability(SOME_CAP, "SOME_VALUE_FROM_CONFIGURATION");
您还可以像@ dangi13答案中那样设置自定义Webdriver:
WebDriverRunner.setWebDriver(myDriverWithExtension);
答案 1 :(得分:1)
我不知道如何在硒硒中做,但是您可以像这样在硒中添加扩展名:
public static WebDriver getChromeDriverWithAdblockCrx() {
System.setProperty("webdriver.chrome.driver", "src//main//resources//chromedriver.exe");
DesiredCapabilities capabilities = new DesiredCapabilities();
ChromeOptions options = new ChromeOptions();
options.addExtensions(new File("src//main//resources//uBlock Origin.crx"));
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
return new ChromeDriver(capabilities);
}
希望对您有帮助:)。
答案 2 :(得分:1)
@sers,@ dangi13非常感谢!
但是没有从Configuration.browserCapabilities
中添加功能。我写了以下代码:
@BeforeClass
public static void setUp() {
Configuration.browser = "chrome";
ChromeOptions options = new ChromeOptions();
options.addExtensions(new File("src/main/resources/uBlock Origin.crx"));
Configuration.browserCapabilities = new DesiredCapabilities();
Configuration.browserCapabilities.setCapability(ChromeOptions.CAPABILITY, options);
}
在github上提到的已知问题:https://github.com/codeborne/selenide/issues/676
作为workarond,我使用以下选项:
@BeforeClass
public static void setUp() {
System.setProperty("webdriver.chrome.driver", "src/main/resources/chromedriver.exe");
Configuration.browser = "chrome";
ChromeOptions options = new ChromeOptions();
options.addExtensions(new File("src/main/resources/uBlock Origin.crx"));
WebDriver webDriver = new ChromeDriver(options);
setWebDriver(webDriver);
}