How to wait until the download finish?

9,228 views
Skip to first unread message

Peng Yu

unread,
Oct 10, 2011, 1:44:59 AM10/10/11
to Selenium Users
Hi,

I load a custom profile which allows me to download file without
having to click OK each time.

firefox_profile=FirefoxProfile(profile_directory='<...>/8h60h0gu.no-download-dialog')
driver = webdriver.Firefox(firefox_profile=firefox_profile)


Then, I click the download button, the file will be downloaded automatically.

driver.find_element_by_css_selector('input[value="Download"]').click()

Then I try to mv the downloaded file. However, the download will take
some time, so the following command will not work correctly as the
download hasn't been finished when it tries to move the file. I'm
wondering how to wait until the file has been finished and then move
the file. (I don't want to wait for a fixed amount time, as I don't
know how the download will take).

shutil.move(default_download_path, dest)

Does anybody have any suggestions? Thanks!

--
Regards,
Peng

Yeshwant Murali

unread,
Oct 10, 2011, 5:12:00 AM10/10/11
to seleniu...@googlegroups.com
Hi,
Write a 'FOR' loop verifying for the download pop-up. If the pop-up is not present, then you can proceed with moving the downloaded content.
Note: Assuming that there will a download pop-up present until the download completes.
Hope this will help you
Thank you,
Yeshwant


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.


Sel List

unread,
Oct 10, 2011, 5:29:24 AM10/10/11
to seleniu...@googlegroups.com
periodically check whether the <filename>.part is present in the directory where its being download.. if yes.. wait for a few more seconds then check again.

If its not present, firefox has completed downloading the file.

-Regards


On Mon, Oct 10, 2011 at 11:14 AM, Peng Yu <peng...@gmail.com> wrote:

Peng Yu

unread,
Oct 10, 2011, 7:02:37 AM10/10/11
to seleniu...@googlegroups.com
This seems to be a little waste. I guess although selenium can control
firefox, but firefox can not send messages back to selenium. If so, is
it possible to add such capability (not sure how to add such feature,
but I'd like to have it)?

--
Regards,
Peng

Enix Shen

unread,
Oct 10, 2011, 2:14:18 AM10/10/11
to seleniu...@googlegroups.com
When clicking download button, you could make your main thread hang and start up a new thread to monitor whether the file is created.

Once file is found, it should notify main thread.

Thanks

Peng Yu

unread,
Oct 10, 2011, 8:37:52 AM10/10/11
to seleniu...@googlegroups.com
When you say "monitor" do you mean I need to use a loop to
periodically check if the file is created?

--
Regards,
Peng

Enix Shen

unread,
Oct 10, 2011, 10:20:48 PM10/10/11
to seleniu...@googlegroups.com
yes

Sel List

unread,
Oct 11, 2011, 1:10:09 AM10/11/11
to seleniu...@googlegroups.com
better than waiting a fixed amount of time eg 3 minutes when your download could be over in a few seconds :)

as for requesting new functionality.. jira is always there..

-Regards
Reply all
Reply to author
Forward
0 new messages