使用Chrome浏览器在Selenium中验证PDF [英] validate pdf in Selenium using chrome browser

查看:545
本文介绍了使用Chrome浏览器在Selenium中验证PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我点击页面中的链接时,PDF会打开。我需要使用C#中的Selenium来验证此PDF文件的内容。



我可以在Firefox 25中使用pdf.js处理此问题。在Firefox中,这个PDF的内容以HTML格式显示,因此,使用isTextPresent,我可以验证PDF内容是否正确。



但Chrome开启PDF在我的浏览器中,它不显示PDF内容作为单独的元素。是否有任何插件/设置更改可以让我在Chrome浏览器中将html视为html? 也适用于Chrome - 请参阅Chrome网上应用店中的 PDF查看器



我建议使用以下URL加载PDF: chrome-extension://oemmndcbldboiebfnladdacbdfmadadm/content/web/viewer.html?file = < PDF文件位置的网址编码版本>



显示如前所示的URL的原因是,如果PDF网址在扩展程序加载前访问 ,然后触发默认PDF行为(在Chromium中,该文件在Chrome中下载,使用Chrome内置的PDF查看器显示)。

加载PDF.js后,您可以直接在多功能框中输入PDF文件的URL,扩展程序会自动检测PD F文件并呈现结果(基于MIME类型)。


When I click on a link in a page, a PDF opens. I need to validate the contents of this PDF file using Selenium in C#.

I'm able to handle this in Firefox 25(using pdf.js). In firefox, the contents of this pdf are displayed in html and hence, using isTextPresent, I am able to validate if the pdf contents are correct.

But, though Chrome opens the pdf in my browser, it does not show the pdf contents as separate elements. Is there any plugin/ setting change that can be done for me to view the pdf as html in Chrome browsewr

解决方案

PDF.js is also available for Chrome - see PDF Viewer in the Chrome Web Store.

I suggest to load the PDF using the following URL: chrome-extension://oemmndcbldboiebfnladdacbdfmadadm/content/web/viewer.html?file=<URL-encoded version of PDF file's location>.

The reason for explicitly putting the URL as shown before is that if the PDF url is visited before the extension is loaded, then the default PDF behavior is triggered (in Chromium, the file is downloaded, in Chrome, it's displayed using Chrome's built-in PDF Viewer).
After the PDF.js is loaded, you can directly type the URL for a PDF file in the omnibox, the extension automatically detects PDF files and renders the result (based on MIME-type).

这篇关于使用Chrome浏览器在Selenium中验证PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆