My Python-Selenium script is downloading the particular file but the file is taking long time to start and get completed downloaded. It starts after clicking in 25/30 seconds and completed in 50/55/60 seconds which is varied. I want to print the name of most recent file after download completion and quit browser afterwords.
I am using glob.glob but it is giving me an error as empty value in max for below code as it executes before the download completion.
mypath = "C:/Users/Desktop/"*.xlsx"
ReportFile = (max(glob.glob(mypath), key=os.path.getmtime))
print(ReportFile)
driver.quit()
OR
list_of_files = glob.glob('C:/Users/Desktop/*.xlsx')
latest_file = max(list_of_files, key=os.path.getmtime)
print (latest_file)
driver.quit()
Currently I am using below code.
time.sleep(100)
driver.quit()
but it is something which is not acceptable as the time download is fluctuating and possibility of failure in the script. I tried with lambda function also but that is also not working.