我试图点击一个带有此按钮的按钮
public void clickDownloadButton() {
WebDriverWait wait = new WebDriverWait(driver, 15);
wait.until(ExpectedConditions.elementToBeClickable(downloadTransactionsButton)).click();
System.out.println("Clicking download transactions button...");
}
单击该按钮后,将打开一个新窗口并下载该文件。如何确保文件下载成功?
答案 0 :(得分:1)
我认为这会有所帮助。
String user = System.getProperty("user.name");
//Assuming your download location is the default location
File f = new File("C:/users/" + user + "/Downloads/NameOfYourDownloadedFile.fileType");
if (f.exists() && !f.isDirectory()) {
System.out.println("File downloaded successfully...");
/*If you have to run the test multiple times,
you may want to delete the file once it's downloaded so*/
if (f.delete()) {
System.out.println("File Removed...");
} else {
System.out.println("Failed to delete the file...");
}
} else {
System.out.println("The file was not downloaded...");
}