Detecting a File Downloaded in Selenium Java

How do I verify if a file is being downloaded in Selenium Webdriver C#

var Path = "drive path";
ChromeOptions co = new ChromeOptions();
co.AddAdditionalCapability("download.default_directory", Path);
driver = new ChromeDriver(co);

Then you can you System.IO.DirectoryInfo for retrieving all downloaded file details into Path folder.

How to check if a file has been downloaded successfully with selenium webdriver?

This method work fine for me

public boolean validateFileDownloaded(String downloadPath, String fileName) {
for (int k = 0; k< 60; k++) {
File dir = new File(downloadPath);
File[] dirContents = dir.listFiles();
if(dirContents == null){
continue;
}
for (File dirContent : dirContents) {
if (dirContent.getName().contains(fileName)) {
return true;
}
}
wait(500);
}
return false;
}


Related Topics



Leave a reply



Submit