Make Selenium wait for a file download to finish Make Selenium wait for a file download to finish selenium selenium

Make Selenium wait for a file download to finish


I would get your automation to move the file into a different location and rename it. System.IO.File.Move("oldfilename", "newfilename"); (C#)

Possibly add a datetime onto the end of the file name.

That way you will never have the problem with duplicate file names and not being able to find the correct file.


double fileSize = file.length();while (!file.exists() || fileSize == 0) { Thread.sleep(2000); }


The best solution is to rename file once it is done with download.

Also I would suggest you to clear any .part file as startup pre-condition. Then before you get into while loop, depending on your computer speed and internet speed, make Thread.sleep(); let's say thread.sleep for 5k miliseconds.

Then enter while loop and look for .part file. Look for file ending with .part. If it exists, wait for another 5k miliseconds.

This solution has worked for me so far.