读取文件内容

时间:2020-02-26 08:12:00

标签: java selenium-webdriver serenity-bdd

  • 工具/技术堆栈:Serenity BDD,Java,Chrome浏览器

自动化方案::用户单击按钮,然后在Chrome的其他标签中打开文件“ https” // appurl / pdfstatement.aspx?xxx ”。 / p>

注意:手动下载文件时,文件以.pdf格式下载

问题:如何从此文件中读取文本

问题1::当鼠标悬停在该部分时,如何单击下载图标/按钮,此按钮出现

尝试解决方案1:,用于尝试下载文件

 WebDriver driver = getDriver();
    Set<String> set = driver.getWindowHandles();
    Iterator it = set.iterator();
    while (it.hasNext()) {
           driver.switchTo().window((String) it.next());
    }
    //String Currentlink = driver.getCurrentUrl();
    driver.getCurrentUrl();
    withAction().moveToElement(target1).build().perform();

Question2 :如何下载文件而不在下一个标签页中打开

尝试解决方案2:将chrome偏好设置禁用为pdfj.disabled = true,但仍在新标签页中打开文件

String userDir = System.getProperty("user.home")+"\\Downloads";

        try {

        PDDocument document = null;             
               document = PDDocument.load(fp);                      
               String pdfContent = new PDFTextStripper().getText(document);*/

               //Loading an existing document.Code below works if pdf file exists in dir

               File file = new File(userDir+"//PDFStatement.pdf");
              PDDocument document = PDDocument.load(file);

              //Instantiate PDFTextStripper class
              PDFTextStripper pdfStripper = new PDFTextStripper();

              //Retrieving text from PDF document
              String text = pdfStripper.getText(document);
              System.out.println(text);

              //Closing the document
              document.close();

尝试过的解决方案3:使用wget下载文件 C:> cmd / c C:\ wget.exe -P C:\ Wget --no-check-certificate https://appUrl/PDFStatement.aspx?registrationid=xxxx&facilitycode=xxxx&TranType=PDF

这不会下载内容或pdf文件,而是下载带有某些html标签的“ PDFStatement.aspx@registrationid=xxxxx”文件。

安全性

chrome_preferences.download.default_directory=${user.home}\\Downloads
chrome_preferences.downloadPath=${user.home}\\Downloads
chrome_preferences.download.prompt_for_download=false 
chrome_preferences.pdfjs.disabled=True

我如何实现读取文件内容的目标。除了尝试失败之外,还有什么办法吗?

0 个答案:

没有答案
相关问题