Downloaded Files stored in specific folder in Selenium Webdriver

package webdriver;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;

public class DownloadFile {
	
	static WebDriver driver;
	
	public static String downloadPath = "E:\\Selenium\\DownFiles";

	public static void main(String[] args) throws Exception 
	{		
	
        driver = new FirefoxDriver(FirefoxDriverProfile());
		
	driver.manage().window().maximize();
		
	driver.get("http://spreadsheetpage.com/index.php/file");
		
	driver.findElement(By.linkText("xllightbox.xls")).click();
		
	driver.quit();

	}
	public static FirefoxProfile FirefoxDriverProfile() throws Exception 
	{
        FirefoxProfile profile = new FirefoxProfile();
        
        profile.setPreference("browser.download.folderList", 2);
        
        profile.setPreference("browser.download.manager.showWhenStarting",false);
        
        profile.setPreference("browser.download.dir", downloadPath);
        
        profile.setPreference("browser.helperApps.neverAsk.openFile","text/csv,application/x-msexcel,application/excel,application/x-excel,application/vnd.ms-excel,image/png,image/jpeg,text/html,text/plain,application/msword,application/xml");
        
        profile.setPreference("browser.helperApps.neverAsk.saveToDisk","text/csv,application/x-msexcel,application/excel,application/x-excel,application/vnd.ms-excel,image/png,image/jpeg,text/html,text/plain,application/msword,application/xml");
        
        profile.setPreference("browser.helperApps.alwaysAsk.force",false);
        
        profile.setPreference("browser.download.manager.alertOnEXEOpen",false);
        
        profile.setPreference("browser.download.manager.focusWhenStarting",false);
        
        profile.setPreference("browser.download.manager.useWindow",false);
        
        profile.setPreference("browser.download.manager.showAlertOnComplete",false);
        
        profile.setPreference("browser.download.manager.closeWhenDone", false);
        
        return profile;
    }
	
}

 

Leave a Reply

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