How to change chrome download path using selenium

How to change chrome download path using selenium
How to change chrome download path using selenium

We can change our chrome download folder location from chrome settings and provide our desired location, but in case of automation, we need to change our download location dynamically. Suppose we need to download a file from an application and need to verify the downloaded file is a valid file or not. We have different API or jars are available to verify the document. I will discuss this verification in my later post. First, we need to download the file in a folder and folder will be created in runtime may be based on timestamp. So you can understand download path will be different every run. 

There is the code which will set the chrome download path runtime. 

 public WebDriver driver;  
 System.setProperty("", driverPath+"chromedriver.exe");  
 HashMap<String, Object> chromePrefs = new HashMap<String, Object>();  
 chromePrefs.put("profile.default_content_settings.popups", 0);  
 chromePrefs.put("download.default_directory", downloadFilepath);  
 ChromeOptions options = new ChromeOptions();  
 options.setExperimentalOption("prefs", chromePrefs);  
 DesiredCapabilities cap =;  
 cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);  
 cap.setCapability(ChromeOptions.CAPABILITY, options);  
 System.setProperty("", driverPath+"chromedriver.exe");  
 driver = new ChromeDriver(options);  

Hope it will solve your problem. 

your ad