How to open pdf in chromedriver 2.15 without downl

2019-06-26 03:19发布

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?

2条回答
Anthone
2楼-- · 2019-06-26 03:51

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.

查看更多
Viruses.
3楼-- · 2019-06-26 04:01

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.

查看更多
登录 后发表回答