Once clicking a download button, files will be downloaded. Before executing next code, it needs to wait until the download completes.
My code looks like this:
<
import time
from os import walk
download_dir = 'path\\to\\download\\folder'
def check_if_download_folder_has_unfinished_files():
for (dirpath, dirnames, filenames) in walk(download_dir):
return str(filenames)
def wait_for_files_to_download():
time.sleep(5) # let the driver start downloading
file_list = check_if_download_folder_has_unfinished_files()
while 'Unconfirmed' in file_list or 'crdownload' in file_list:
file_list = check_if_download_folder_has_unfinished_files()
time.sleep(1)
if __name__ == '__main__':
wait_for_files_to_download()