I'm using selenium webdriver to do some downloading using firefox. At the moment my script waits for a specific time after download has inititated and then close the firefox. I want to know if there is a way to configure firefox to automatically close on download completions? Or using selenium webdriver, can I check if download has been completed? I don't want to use any add on, as it might add dependency in my script. I cant use wget/curl etc to download the files. Thanks in advance
3 Answers
What Ignacio Contreras said. Polling the download path is possibly the best (most robust) solution.
Alternative #1:
Use a FirefoxProfile
with Download Statusbar addon. It has a handy option to "Continue downloading in Download manager after window has been closed" (or something very similar), so that it will keep Firefox running in the background until the download has been finished.
Alternative #2:
Download the file directly using this (or any other similar WebDriver-friendly tool) ... or this, if you can. That will totally cut Firefox out of the process.

- 1
- 1

- 37,768
- 12
- 121
- 145
-
Just as a data point, the link to the download statusbar points to an older plugin. On installing it (because I wasn't paying too close attention), Symantec freaks out because its about page is laden with adware. Updated link: https://addons.mozilla.org/en-us/firefox/addon/download-status-bar/ – jim_carson Feb 26 '15 at 16:00
You can use Selenium WebDriver API's WebDriverWait class to do the polling using the following code:
(new WebDriverWait(driver, 180, 10)).until(new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver d) {
return !downloadedFilePart.exists();
}
});
The above code checks for file with .part extension program is downloading for every 10 seconds until either download completed or timed out after 3 minutes.

- 101
- 1
- 5
I'm not sure if this would work, but have you considered exploring trhough Firefox the download location? polling it until you see the download has been completed.
If I'm not wrong, when the file it's been downloaded, there should be an extra file with the extension .part.
Something like this (pseudocode):
...
WebDriver poller = new FirefoxDriver()
poller.get("path to download folder");
while ("file with .part extension is present") {
// Wait/sleep some time
// Refresh poller
}
// close downloading firefox instance
firefox.quit();
// close the polling instance
poller.quit();
Hope it helps

- 511
- 1
- 5
- 21
-
Thanks Ignacio. But the problem is that, at a given time, multiple instances of firefoxes can be running. The multiple firefox instances can be downloading to same location. – Red Devil May 24 '12 at 10:15
-
well, you make that each of these instances poll the download location looking for the .part file of their respectives downloads (if the instances are thrown from separated instances of java running code). Or if all of them are executed from the same program, you can create an array of filenames so you can throw an unique polling driver that closes each firefox instance when needed. – Ignacio Contreras Pinilla May 24 '12 at 10:34