Download File in Selenium

Price: INR 8,999.00
Price: INR 14,999.00
Was: INR 16,999.00

Let’s see How to Download File in Selenium. Many times we need to download files and verify that download functionality is working fine or not.

In this tutorial, We will see how can we manage the file download using selenium WebDriver.


In simple terms, we can do this task using AutoIT or Skuli with selenium. But we will discuss the selenium integration with these tutorials later.

Here, we will see how can we download the file using Selenium with Firefox.


To Download file with selenium, We need to do some settings to the browser using Firefox profile using preferences.

So that it automatically download the files to the defined folder. Then we will write code to check if the folder is downloaded or not.

Now let’s understand the above code. Let’s understand our function FirefoxDriverProfile()


1. setPreference(“”, 2) – The value can be set to either 0, 1, or 2. When set to 0, Firefox will save all files downloaded via the browser on the user’s desktop. When set to 1, these downloads are stored in the Downloads folder. When set to 2, the location specified for the most recent download is utilized again.


2. setPreference(“”, false) – The Preference in Firefox’s about config interface allows the user to specify whether or not the Download Manager window is displayed when a file download is initiated.


3. browser. download. dir -The last directory used for saving a file.


4. browser.helperApps.neverAsk.openFile -A comma-separated list of MIME types to open directly without asking for confirmation.


5. browser.helperApps.neverAsk.saveToDisk – A comma-separated list of MIME types to save to disk without asking what to use to open the file. The default value is an empty string.


6. browser.helperApps.alwaysAsk.force –  Always ask what to do with an unknown MIME type, and disable the option to remember what to open it with False.


7. – This method warns the user to attempt open .exe file.

True (default): warn the user attempting to open an executable from the Download Manager.
False: display no warning and allow the executable to be run.


8. – This is to set the download manager window.

True: Set the Download Manager window as active when starting a download.
False (default): Leave the window in the background when starting a download.


9. – A boolean value indicating whether or not to use the Downloads window (true) or display download status in the status bar (false) in the browser window.
The default value is true.


10. – A boolean value that indicates whether or not an alert should be shown when downloads complete.
The default value is true.


10. – A boolean value indicating whether or not the Downloads window should close automatically when downloads are completed.
In Thunderbird the default value is true.
In Other Applications the default value is false.


So this is the way, How can we download the file using selenium without any third party tool integration.

Don’t worry later we will discuss the Selenium with AutoIT, Skuli and Robots as well.

0 Comment

Leave a Reply