[英]How to download generated pdf file from webapp and attach it to test results in Visual Studio using Selenium C#
I'm automating a web app using selenium c#, and one of the requirements is to attach an generated PDF file to the test results file in visual studio. 我正在使用Selenium C#自动化Web应用程序,其中一项要求是将生成的PDF文件附加到Visual Studio中的测试结果文件。 I'm able to download the PDF by clicking on the respective button. 我可以通过单击相应的按钮来下载PDF。 Note that I don't have the download link URL since the PDF is generated at run time using JavaScript calls. 请注意,我没有下载链接URL,因为PDF是在运行时使用JavaScript调用生成的。 So please help me with this question. 因此,请帮助我解决这个问题。
If you are looking for a simple solution, checkout the tika package, really straight forward for reading pdfs. 如果您正在寻找一个简单的解决方案,请查看tika软件包,真的很简单,可以阅读pdf。
from tika import parser
raw = parser.from_file('sample.pdf')
print(raw['content'])
Multi - page pdf can be extracted as text at single stretch instead of giving individual page number as argument using below code 多页pdf可以单次提取为文本,而无需使用以下代码将单个页码作为参数
import PyPDF2
import collections
pdf_file = open('samples.pdf', 'rb')
read_pdf = PyPDF2.PdfFileReader(pdf_file)
number_of_pages = read_pdf.getNumPages()
c = collections.Counter(range(number_of_pages))
for i in c:
page = read_pdf.getPage(i)
page_content = page.extractText()
print page_content.encode('utf-8')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.