How to verify that file is downloaded successfully or not in Selenium?

you can use custom expected condition:## to check if file is present

using:

import java.io.File;

private ExpectedCondition<Boolean> filepresent() {
    return new ExpectedCondition<Boolean>() {
        @Override
        public Boolean apply(WebDriver driver) {
            File f = new File("F:\program.txt"); 
            return f.exists();
        }
        
        @Override
        public String toString() {
          return String.format("file to be present within the time specified");
        }
    };
}

we ceated a custom expected condition method now use it as:

and in code wait like:

wait.until(filepresent());

Output:

Failed:

enter image description here

Passed

enter image description here