How to Download files in Selenium Webdriver

Hello Welcome to Selenium tutorial, today we will see How to Download files using Selenium Webdriver.

In previous post, we have seen how to upload files using robot class and upload files using AutoIT. Today we will see some different scenario we will see downloading files in Selenium.

Sometime in your application, you have to control some scenario in which you need to download some files by clicking on some link or some button.

Once you start download files/application, you will get one confirmation window, which will ask to save, file or cancel here Webdriver stuck because this is Window’s Pop up. Selenium can handle only Web browser automation not windows based application. Refer below screenshot for more information.

Here download files window is displayed if you try to inspect using firebug you will not get any locators for them.
How to Download files using Selenium

So using some browser settings (firefoxprofile) we can skip that confirmation window and we can continue with our script.

Here is some setting that we need to modify let’s see how to check these setting

How to Download files in Selenium Webdriver

1- Open Firefox browser and in url box type about:config and press enter

2- In Search bar type neverask and enter, here you will find some settings(refer below screenshot)
How to Download files using Selenium

Now you can see here value is blank so we need to mention which type of file it will not ask if download starts in case.

Note- In this post I am giving values for .exe file(application), in your case if you want to download pdf, excel file etc. you need to mention values (MIME type).

Here you can find their MIME type that will be the values for these settings.

http://www.sitepoint.com/web-foundations/mime-types-complete-list/

How to Download files in Selenium Webdriver

Step 1- Create a firefox Profile.

Step 2- set Preferences as per requirement.

Step 3- Open Firefox with firefox profile.

Let us implement the same through Script.

Note- This script will download Adobe Reader from Filehippo.com

package blog;

 

If you run above code files will be download automatically and download window will not appear 🙂

Please comment below if you have any issue in Selenium. Thanks for visiting my blog keep in touch.

Bye.

 

31 Comments

  1. Tarun
  2. suresh
  3. shilpa
  4. Sreenath
  5. Priyanka Chouhan
  6. Vasu
  7. Suresh Sharma
  8. Learner
  9. divakar
  10. Nitin
  11. vivek
  12. sivakrishna
  13. QualityAnalyst
  14. sateesh
  15. Omprakash

Leave a Reply