Пожалуйста, смотрите данное изображение [https://i.stack.imgur.com/VoiQE.png] , так как каждый файл успешно загружается отдельно со следующим кодом:
buttonDownload.click(); //This is the code just to download 'Image' option.
selectImageOption.click();
Thread.sleep(2300);
selectImageOptionToDownload.click();
Чтобы проверить, было ли изображение успешно загружено или нет? Пробовал 2 разных способа, но в обоих случаях выдает ошибку «Null Pointer Exception».
public void isFileDownloaded() {
File downloadFolder = new File("C:\\Users\\dp\\Download"); //Path of default 'Download' folder.
List<String> namesOfFiles = Arrays.asList(downloadFolder.list()); //At this line getting an error "Null Pointer Exception"
{
if(namesOfFiles.contains("CM Supervisor Dashboard.png"))
{ System.out.println("Downloaded");}
else
System.out.println("not downloaded");
}
}
Другая логика c Я попробовал:
public boolean isFileDownloaded(String DownloadPath, String fileName) {
boolean flag = false;
File dir = new File("C:\\Users\\dp\\Download");
File[] dir_contents = dir.listFiles();
for (int i = 0; i < dir_contents.length; i++) { //At this line getting an error 'Null Pointer Exception"
if (dir_contents[i].getName().equals("Dashboard"))
return flag=true;
}
return flag;
}