How to open pdf in chromedriver 2.15 without downloading it

二次信任 提交于 2019-12-12 11:50:23

问题


I recently upgraded to Chromedriver 2.15

Now, when I click a link to a pdf file it is auto-downloading instead of displaying in a new tab as before.

<a id="my_pdf_file" format="pdf" target="_blank" href="/my_pdf_file.pdf">My PDF File</a>

Is there a way to resume the old behavior of displaying the pdf in a new tab?


回答1:


This is currently an open issue with Chrome, not 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.

I updated to the latest version of the dev branch of Chrome 44.0.2391.0 dev-m (64 bit), ran a test in Selenium that opens a PDF, and can confirm that PDFs are opening in new tabs by default.

This was tested using the following:

Chrome 44.0.2391.0 dev-m (64 bit)
Selenium 2.45
Chrome Driver 2.15

So, you can either use the dev version of Chrome until the release version catches up, try one of the workarounds in the link above, or wait with the knowledge that it will get fixed soon.




回答2:


This is how you define a Chrome profile with Watir

This is the chromedriver capabilities page

I don't see right off the way to enable/disable the Chrome PDF viewer (chrome://plugins/)

But, you can set up your own profile - see the 'Use custom profile' section.



来源:https://stackoverflow.com/questions/29780399/how-to-open-pdf-in-chromedriver-2-15-without-downloading-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!