【问题标题】:PDF is not being opened in Chrome started by Selenium由 Selenium 启动的 Chrome 中未打开 PDF
【发布时间】:2015-07-09 17:12:59
【问题描述】:

我正在使用 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 的默认设置。

【问题讨论】:

标签: java google-chrome pdf selenium selenium-chromedriver


【解决方案1】:

此问题是由最近更改 --test-type 开关的行为引起的。是described in the ChromeDriver issue tracker

解决方法是禁用此开关。这是我的代码更改:

// Add ChromeDriver-specific capabilities through ChromeOptions.
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("excludeSwitches", Arrays.asList("test-type"));
webDriver = new ChromeDriver(options);
webDriver.get(url);

【讨论】:

猜你喜欢
  • 2015-04-09
  • 1970-01-01
  • 2023-01-07
  • 2017-01-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-15
  • 2013-09-17
相关资源
最近更新 更多