简体   繁体   English

如何使用Selenium C#从webapp下载生成的pdf文件并将其附加到Visual Studio中的测试结果

[英]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.

相关问题 如何使用Visual Studio在C#中创建硒测试 - how to create a test for selenium in C# using visual studio 在Visual Studio中使用C#和ChromeDriver进行MS Test的Selenium WebDriver - Selenium WebDriver with MS Test using C# and ChromeDriver in Visual Studio 如何使用以C#编写的Selenium在所需位置从弹出窗口下载并保存Excel和pdf文件 - How to download and save excel and pdf file from pop-up in a desired location using Selenium written in C# 如何使用Visual Studio中的Selenium在C#中的私有IE浏览器中运行测试? - How can I run a test in a private IE browser in C#, using Selenium in Visual Studio? 如何在 C# 中使用 Selenium 从 Chrome 下载 PDF - how can i download a PDF from Chrome using Selenium in C# 如何下载 PDF selenium 和 C# - How Download PDF selenium and C# 如何使用asp.net c将使用jsPDF生成的PDF附加到邮件中 - How to attach a PDF generated using jsPDF to the mail using asp.net c# 如何使用 c# 在 Visual Studio 2017 中为 1 个 selenium 项目创建 .exe 文件,其中包含多个类 - how to create .exe file in visual studio 2017 for 1 project of selenium using c# having multiple class within it 使用 C# 从 API 下载 PDF 文件 - Download PDF File from API Using C# 如何将生成的pdf文件作为附件发送到C#的电子邮件中? - How to send generated pdf file as attachment in email from C#?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM