Wait for Download to finish in selenium webdriver JAVA

后端 未结 13 1679
醉话见心
醉话见心 2020-12-01 14:38

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:

<
13条回答
  •  北海茫月
    2020-12-01 15:02

    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()
    

提交回复
热议问题