解決方式是加入--always-authorize-plugins 這個參數。
程式碼如下:
ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized");
options.addArguments("--always-authorize-plugins");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setJavascriptEnabled(true);
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = null;
try {
driver = new RemoteWebDriver(new URL("http://localhost:9515"), capabilities);
} catch (MalformedURLException e) {
e.printStackTrace();
}
options.addArguments("start-maximized");
options.addArguments("--always-authorize-plugins");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setJavascriptEnabled(true);
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = null;
try {
driver = new RemoteWebDriver(new URL("http://localhost:9515"), capabilities);
} catch (MalformedURLException e) {
e.printStackTrace();
}
沒有留言:
張貼留言