如何使用 selenium webdriver 检查文件是否已成功下载?

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

如何使用 selenium webdriver 检查文件是否已成功下载?

这个方法很适合我

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;
}