2015-10-28 49 views
0

目前即时使用Selenium Webdriver for c#和PDFBox自动化报表的PDF文本。现在,使用PDFBox,我们可以通过URL = new URL(“pdf of the link”)解析PDF链接。但是,这不需要任何先决条件即可直接使用URL链接。PDF自动化使用URL从已打开的内容继续

如果我使用直接URL地址访问pdf,则会出现“资源未找到”错误。我基本上需要登录到应用程序,并选择我需要的报告,以加载实际的PDF。它具有相同的地址,除了它是在应用程序中加载的,而不是直接加载的。我如何将Selenium与PDFbox关联起来,以便代替打开直接转到拒绝权限URL的新URL,它将转到已在屏幕上预装的PDF报告,并使用相同的URL地址?

  URL url = new URL("link of url"); 
    BufferedInputStream input = new BufferedInputStream(url.openStream()); 
     PDFParser parsepdf = new PDFParser(input); 
     parsepdf.parse(); 
     textofpdf = new PDFTextStripper().getText(parsepdf.getPDDocument()) 

所以基本上我有一个Selenium Test类,它执行登录和打开报告的功能。之后,我打电话给上面的PDFParse方法。此方法当前的功能就好像加载了新的URL,而不是继续当前的Selenium会话。

+0

登录,您使用的是相同的浏览器访问URL PDF或打开一个新的浏览器后? – LINGS

+0

在同一浏览器中,它会自动在不同的选项卡中打开。 –

回答

0

块引用

试试这个:

PDFTextStripper pdfStripper = null; 
    PDDocument pdDoc = null; 
    COSDocument cosDoc = null; 
    String parsedText = null; 

     URL url = new URL(strURL); 
     Proxy proxy = new Proxy(Proxy.Type.HTTP, new   InetSocketAddress("172.18.65.50", 8080)); 
     URLConnection urlc = url.openConnection(proxy); 
     urlc.addRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0a2) Gecko/20110613 Firefox/6.0a2"); 
     RandomAccessBufferedFileInputStream file = new RandomAccessBufferedFileInputStream(urlc.getInputStream()); 
     PDFParser parser = new PDFParser(file);   
     parser.parse(); 
     cosDoc = parser.getDocument(); 
     pdfStripper = new PDFTextStripper(); 
     pdfStripper.setStartPage(1); 
     pdfStripper.setEndPage(1); 

     pdDoc = new PDDocument(cosDoc); 
     parsedText = pdfStripper.getText(pdDoc);