I want to close browser as soon file download is complete. I have below code but it's not closing browser. I must be wrong somewhere. Please help me.
driver.find_element_by_link_text("[Comma-Delimited Text (CSV)]").click()
while True:
if os.path.isfile('C:\\Python34\\*.part'):
time.sleep(10)
elif os.path.isfile('C:\\Python34\\*.csv'):
break
else:
time.sleep(10)
def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors)
os.path.isfile() does not support glob-style path definitions leading to the loop never exiting.
You need the glob.glob() or fnmatch instead:
You can also use modules like watchdog to monitor changes in a directory:
I have written a download method for zip file download. this could be helpful. after clicking on download button this method will be called and waiting until the download complete
def downloader() :
print("File Download Started.......")
sleep(60)
while True:
file = glob.glob(BASE_FILE_DIR+'*.zip.part')
if file:
print("Download Pending.......")
sleep(60)
continue
else:
print('File Downloaded')
break
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With