我正在使用Selenium和ChromeDriver 2.43.1以及最新的Chrome(在询问排队时版本42.0.2311.135) . 我的Web应用程序生成PDF . 它使用正确的MIME类型发送,并且还可以在Chrome PDF查看器中正确打开 . 但是,当我尝试使用由WebDriver启动的Chrome中的Selenium打开PDF时,它会被下载 .
我相信可能是Selenium或WebDriver用来启动Chrome的一些设置 .
我已经尝试了settings a few switches,但还没有任何效果 . 我的代码:
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
// Add ChromeDriver-specific capabilities through ChromeOptions.
ChromeOptions options = new ChromeOptions();
options.addArguments("--please-make-it-work"); // not a real switch
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
webDriver = new ChromeDriver(capabilities);
webDriver.get(url);
我真正需要的是以“正常”模式启动浏览器 . 它不需要任何配置文件设置,只需要打开PDF的默认设置 .
1 回答
问题是由于最近对
--test-type
开关行为的改变造成的 . 这是described in the ChromeDriver issue tracker .解决方法是禁用此开关 . 这是我的代码更改: