Buy From Flipkart

Friday, 14 February 2014

File Downlaoding using Selenium Webdriver

  File Downlaoding using Selenium Webdriver:

Files downloading using WebDriver is possible by using profile set up in FireFox. Following is the sample code for setting preferences , The important aspect to go with downloading is you need to know the MIME type of the file that you wanted to download.

For Example if you wanted to download .txt (i.e text file) file then you need to add text/plain in the browser.helperApps.neverAsk.saveToDisk preference saveToDisk is the profile preference which excludes windows popup of Open with / save .

you can find the MIME types for different file type in the following link

http://www.freeformatter.com/mime-types-list.html

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

Following is the sample code snippet  for file downloading



       FirefoxProfile profile = new FirefoxProfile();
        String path="d:\\downloads123";
        profile.setPreference("browser.download.folderList", 2);
        profile.setPreference("browser.download.dir", path);
        profile.setPreference("browser.download.manager.alertOnEXEOpen", false);
        profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/msword,application/csv,text/csv,image/png ,image/jpeg, application/pdf, text/html,text/plain,application/octet-stream");
       
     
       
        WebDriver driver = new FirefoxDriver(profile);




Please do comment hear if you have any queries on this topic.


Please do comment for any queries