Rajith
Rajith

Reputation: 51

How to get file download complete status using selenium web driver c#

I am writing a automation script using selenium web driver for downloading multiple files one by one from a web site in Mozilla fire fox. I have downloaded first file successfully and next time I need to wait for download to complete. Can anybody help how to identify an ongoing download is completed using c# selenium web driver.? Since I am not getting the download complete status, I am unable to continue downloading next file.

Upvotes: 5

Views: 8527

Answers (1)

amitbobade
amitbobade

Reputation: 510

Assuming you are testing file downloading in Firefox as you mentioned. Here is an approach to achieve what you want.

  1. Open new window/tab in Firefox and navigate to 'about:downloads' directly. i.e. driver.Navigate().GoToUrl("about:downloads"); You will get the list of downloads (i.e. already downloaded files and the file which is being downloaded currently.) You will have to switch between your site tab and downloads tab.

  2. Now on downloads tab, looking at HTML, you can easily find out in progress download using state or status attributes.

For example, for the first file in the list, if state="0" and/or status contains the text 'remaining', it means downloading is in progress

So you can wait till state becomes state = 1 and/or status does not contain >the text 'remaining'

Refer the attached screen shot. enter image description here

The explanation I gave here looks very high level, but I am sure this approach will work. It is simple too.

Let me know if you have any queries on this.

Upvotes: 14

Related Questions