In Selenium WebDriver, downloading a file is not as easy as uploading a file. Follow these simple steps in order to download a file using selenium WebDriver :
1) Launch Eclipse, create project, create a package, and then create a class inside this package. Name this class as “test21.java”.
2) In your script, the first thing you need to do is create FirefoxProfile object. Add the following line of code to create it :
FirefoxProfile profile=new FirefoxProfile();
3) The next step involves setting of preference which you can do by adding the code :
4) Now we need to profile which is to be used, for this we have to pass it in to the driver :
WebDriver driver=new FirefoxDriver(profile);
5) Navigate to the link “http://www.filehippo.com/download_adobe_reader_unpublish” and click on the “Download Latest Version” option. The download will start.
6) Here I have taken an example of downloading .exe file, if the type of file you want to download is not an .exe file, if it is some other file like pdf or doc. You need to do the settings in Firefox before you proceed with your test script. For the settings, launch Firefox and type about:config in the URL.
7) In the search bar, write neverask and hit enter button. Under the Value, write the extension of the type of file you want to download.
That’s all in downloading file using selenium web driver…!!!