我最近升级到 Chromedriver 2.15
现在,当我单击 pdf 文件的链接时,它会自动下载,而不是像以前一样显示在新选项卡中。
<a id="my_pdf_file" format="pdf" target="_blank" href="/my_pdf_file.pdf">My PDF File</a>
有没有办法恢复在新选项卡中显示 pdf 的旧行为?
最佳答案
这是目前 Chrome 的一个 Unresolved 问题,而不是 Chromedriver:
Unable to open a PDF file in chrome since upgrading to v 42.0.2311.90
At some point between M41 and M42, the behavior of the --test-type switch was changed so that PDFs are downloaded instead of displayed.
我更新到最新版本的 Chrome 开发分支
44.0.2391.0 dev-m (64 bit)
,在 Selenium 中运行了打开 PDF 的测试,并且可以确认默认情况下 PDF 正在新选项卡中打开。这是使用以下方法测试的:
Chrome 44.0.2391.0 dev-m (64 bit)
Selenium 2.45
Chrome Driver 2.15
因此,您可以使用 Chrome 的开发版本,直到发布版本 catch 来,尝试上面链接中的一种解决方法,或者等待它很快得到修复。
关于pdf - 如何在不下载的情况下在 chromedriver 2.15 中打开 pdf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29780399/