As we understand we cannot model OS activities with Selenium. We use AutoIt tool to upload docs (when it’s not possible to achieve upload using sendKeys method). We’ve discussed Using AutoIT Program in earlier tutorials and uploading a file using using Webdriver Sendkeys system.

To manage Download functionality with selenium training, to ensure that it automatically download the files to the folder that is defined, we should do some settings to the browser using Firefox profile using preferences. We can write code to test in the event the folder is downloaded or not.

Below is the example application to download a file

package com.pack;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.firefox.FirefoxDriver;

import org.openqa.selenium.firefox.FirefoxProfile;

import org.testng.annotations.Test;

public class FileDownloadExample {

public static String downloadPath = “D:\\seleniumdownloads”;


public void testDownload() throws Exception {

WebDriver driver = new FirefoxDriver(FirefoxDriverProfile());





public static FirefoxProfile FirefoxDriverProfile() throws Exception {

FirefoxProfile profile = new FirefoxProfile();

profile.setPreference(“”, 2);

profile.setPreference(“”, false);

profile.setPreference(“”, downloadPath);





profile.setPreference(“browser.helperApps.alwaysAsk.force”, false);

profile.setPreference(“”, false);

profile.setPreference(“”, false);

profile.setPreference(“”, false);

profile.setPreference(“”, false);

profile.setPreference(“”, false);

return profile;



We are going to describe you the settings that we’ve place to Firefox browser.

setPreference(“”, 2);

Default Value: 1

The value of may be set to either 0, 1, or 2. Firefox will save all files downloaded through the browser on the user ‘s background when set to 0. These downloads are kept in the Downloads folder when set to 1. The place established for the latest download is used again when set to 2.

setPreference(“”, bogus);

Default Value: true

The Setting in Firefox’s about:config interface permits the consumer to set if the Download Manager window is shown when a file download is started.

browser. helperApps. always Ask. Drive

Authentic: Constantly inquire how to proceed with the unknown MIME kind, and disable alternative to recall what to open it with False (default): Opposite of above

browser. helperApps. neverAsk. saveToDisk

A comma-separated list of MIME types without asking things to use to open the file to save to disc. Default value is an empty string.

browser. helperApps. neverAsk. openFile

A comma-separated list of MIME types to open without asking for confirmation. Default value is an empty string.

browser. download. dir

The past directory useful for saving a file in the “What should (browser) do with this particular file?” dialog.

True (default option): warn the user trying to open an executable in the Download Manager

False: let executable to be run and display no warning

Note: In Firefox, this may be altered by checking the “Do Not ask me this again” box when you strike the alarm.

browser. download. manager. closeWhenDone

Authentic: Close the Download Manager when all downloads are complete

False (default option): Reverse of the preceding

browser. download. manager. focus When Starting

Authentic: Place the Download Manager window active when starting a download

False (default option): When starting a download, leave the window in the background
Hope this helps you.

Leave a Reply

Your email address will not be published. Required fields are marked *