在读取文件内容时遇到问题。
步骤:用户单击按钮 在另一个标签中打开文件。URL为“ https://appurl/PDFStatement.aspx?registrationid=xxxx&facilitycode=xxxx&TranType=PDF”
2个问题
第一季度。如何从打开它的选项卡中下载此文件。将鼠标悬停在面板上后,我无法单击下载图标。 注意:手动进行测试并单击下载图标时,下载的文件为abc.pdf
尝试到现在
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();// target1 is the element I was trying to hover to to get the download icon visible
第二季度。我尝试在chrome中设置以下首选项,以便在单击按钮时下载文件(以避免在新标签页中打开文件。
尝试到现在
String userDir = System.getProperty("user.home")+"\\Downloads";
System.out.println("pdfj"+System.getProperty("pdfjs.disabled"));
try {
/* Code below works when I have file downloaded manually and available
//Loading an existing document
//File file = new File("C:/PdfBox_Examples/new.pdf");
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();
我可以实现目标的另一种方法。 我在Java中使用BDD Serenity。
Serenity.property如下
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
这对我来说阻止了很多测试。请帮助