# Changing the download path dynamically during runtime

**URL:** <https://forum.katalon.com/t/changing-the-download-path-dynamically-during-runtime/20758>\
**Category:** Web Testing\
**Tags:** katalon-studio\
**Created:** [March 8, 2019, 3:33am UTC](https://forum.katalon.com/t/changing-the-download-path-dynamically-during-runtime/20758 "2019-03-08T03:33:23Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![porte.marvin](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/porte.marvin/32/12334_2.png) [@porte.marvin](https://forum.katalon.com/u/porte.marvin)\
**Post date:** [March 8, 2019, 3:33am UTC](https://forum.katalon.com/t/changing-the-download-path-dynamically-during-runtime/20758/1 "2019-03-08T03:33:23Z")

</div>

Hi All,

I just want to ask if it is possible to change the download directory by passing a variable instead of a fixed download path during runtime? (e.g. C:\users\user\Downloads)

I tried passing it through settings but unfortunately there is no variable Type and I am guessing you can only put a fixed path there.

The reason behind is I want to create a temporary folder everytime i run the test is because I have a lot of files to be downloaded and I want to separate them per category and delete them after execution.

So far i tried RunConfiguration.setWebDriverPreferenceproperty like this:

 ![image](https://europe1.discourse-cdn.com/katalon/original/2X/3/3ea93a5ce770a0d498046baf0a35fbef0aa44b4d.png)

Unfortunately, it’s not working. I am thinking that I should pass “prefs” on the first parameter but not sure what to pass on the second as it should be a dictionary Type.

Thanks!

---

<div class="post-metadata">

**Author:** ![Russ\_Thomas](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/russ_thomas/32/11884_2.png) [@Russ\_Thomas](https://forum.katalon.com/u/Russ_Thomas)\
**Post date:** [March 8, 2019, 7:38pm UTC](https://forum.katalon.com/t/changing-the-download-path-dynamically-during-runtime/20758/2 "2019-03-08T19:38:52Z")

</div>

Maybe there is something in this post that might help…

> [@Desired Capabilities - The Missing Manual](http://forum.katalon.com/t/desired-capabilities-the-missing-manual/20748):
>
> One of the biggest hurdles with using Katalon/Webdriver is setting the appropriate Desired Capabilities that configure various browser settings programmatically. There are a couple of reasons for this: 1.) Browsers do not expose these back-end properties in the settings menu. Instead, they offer a user-friendly GUI for configuring settings that are based on these properties. This of course makes sense for 99.9999% of browser users, but isn’t helpful for us. 2.) The appropriate Desired Capabili…

---

<div class="post-metadata">

**Author:** ![porte.marvin](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/porte.marvin/32/12334_2.png) [@porte.marvin](https://forum.katalon.com/u/porte.marvin)\
**Post date:** [March 11, 2019, 6:00am UTC](https://forum.katalon.com/t/changing-the-download-path-dynamically-during-runtime/20758/3 "2019-03-11T06:00:58Z")

</div>

Hi Russ\_Thomas,

Thanks for the post.

Though I was finally able to make it work by passing HashMap instead of the contents.

now I was finally able to use this custom method to make the download path “dynamic” by passing a variable instead of setting it up hardcoded under settings.

image|690x293

---

<div class="post-metadata">

**Author:** ![shilpi1](https://avatars.discourse-cdn.com/v4/letter/s/b3f665/32.png) [@shilpi1](https://forum.katalon.com/u/shilpi1)\
**Post date:** [September 25, 2019, 9:31am UTC](https://forum.katalon.com/t/changing-the-download-path-dynamically-during-runtime/20758/4 "2019-09-25T09:31:17Z")

</div>

Hi porte.marvin, I have to do same, can you please share how you have done this.

As of now I am hardcoding downloadpath but it will get changed on other machine, eg username.  
How can i get tha downloadpath on real time and then perform actions using that path.

Please help

---

<div class="post-metadata">

**Author:** ![daniel.h](https://avatars.discourse-cdn.com/v4/letter/d/0ea827/32.png) [@daniel.h](https://forum.katalon.com/u/daniel.h)\
**Post date:** [September 26, 2019, 12:51pm UTC](https://forum.katalon.com/t/changing-the-download-path-dynamically-during-runtime/20758/5 "2019-09-26T12:51:49Z")

</div>

for me this works:

> import org.openqa.selenium.WebDriver  
> import org.openqa.selenium.chrome.ChromeDriver  
> import org.openqa.selenium.chrome.ChromeOptions  
> import com.kms.katalon.core.webui.driver.DriverFactory
> 
> String downloadPath = “C:\customDownloadFolder\”
> 
> Map\<String, Object\> chromePrefs = new HashMap\<String, Object\>()  
> chromePrefs.put(“download.default\_directory”, downloadPath)  
> chromePrefs.put(“download.prompt\_for\_download”, false)
> 
> System.setProperty(“webdriver.chrome.driver”, DriverFactory.getChromeDriverPath())  
> ChromeOptions options = new ChromeOptions()  
> options.setExperimentalOption(“prefs”, chromePrefs)  
> WebDriver driver = new ChromeDriver(options)  
> DriverFactory.changeWebDriver(driver)
> 
> WebUI.navigateToUrl([https://www.katalon.com/](https://www.katalon.com/))  
> // other Test Stuff as usual

---

<div class="post-metadata">

**Author:** ![shilpi1](https://avatars.discourse-cdn.com/v4/letter/s/b3f665/32.png) [@shilpi1](https://forum.katalon.com/u/shilpi1)\
**Post date:** [October 1, 2019, 10:25am UTC](https://forum.katalon.com/t/changing-the-download-path-dynamically-during-runtime/20758/6 "2019-10-01T10:25:07Z")

</div>

Thanks, but I need more validations, it works only for chrome , I have to do for other browsers aswell. So i am trying like below …but not that opens two browsers, one with OpenBrowser and another with ChromeDriver initializing- please help  
def pageload(String browser) {

```
	WebUI.openBrowser('')

	WebDriver driver = DriverFactory.getWebDriver()
	WebUI.closeBrowser()
	println("Driver new is "+ driver)

	long startTime = System.currentTimeMillis()
	println("The Value of brwonser is : "+ browser);
	String downloadPath = RunConfiguration.getProjectDir()+ '/' +'download_Upload/'
	println("The Chrome_Browser Download path is : " +downloadPath)
	Map<String, Object> browserPrefs = new HashMap<String, Object>()
	browserPrefs.put('download.default_directory', downloadPath)
	browserPrefs.put('download.directory_upgrade', true)
	browserPrefs.put('download.prompt_for_download', false)
	if(String.valueOf(driver).contains('chrome')) {
		println("Chrome found")
		System.setProperty('webdriver.chrome.driver', DriverFactory.getChromeDriverPath())
		println("declaring ChromeOptions")
		ChromeOptions options = new ChromeOptions()
		options.setExperimentalOption('prefs', browserPrefs)
		println("calling change web driver")
		driver=new ChromeDriver(options)

		DriverFactory.changeWebDriver(driver)
		println("executed change web driver")
	}
	else {
		DriverFactory.changeWebDriver(driver)
	}

	println("Rest of the program")

	long endTime = System.currentTimeMillis()
	long totalTime = endTime - startTime
	long TimeInSeconds = totalTime / 1000
	def String page_load_time = ("Time to load page " +TimeInSeconds + " in Seconds")
	println (page_load_time)
	WebUI.navigateToUrl(GlobalVariable.url_app_navigator)
	println("Navigate to site")
	WebUI.maximizeWindow()
	WebUI.delay(10)
```

---

<div class="post-metadata">

**Author:** ![shilpi1](https://avatars.discourse-cdn.com/v4/letter/s/b3f665/32.png) [@shilpi1](https://forum.katalon.com/u/shilpi1)\
**Post date:** [October 1, 2019, 10:26am UTC](https://forum.katalon.com/t/changing-the-download-path-dynamically-during-runtime/20758/7 "2019-10-01T10:26:43Z")

</div>

can this be achieved with Desired settings??

---

<div class="post-metadata">

**Author:** ![mdfayaz6138](https://avatars.discourse-cdn.com/v4/letter/m/ea5d25/32.png) [@mdfayaz6138](https://forum.katalon.com/u/mdfayaz6138)\
**Post date:** [May 3, 2020, 12:54pm UTC](https://forum.katalon.com/t/changing-the-download-path-dynamically-during-runtime/20758/8 "2020-05-03T12:54:51Z")

</div>

Hi Marvin, can you please share your working code snippet.?

I have changed the HashMap but it didn’t work, want to know where did I miss by looking at your code.

---

<div class="post-metadata">

**Author:** ![porte.marvin](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/porte.marvin/32/12334_2.png) [@porte.marvin](https://forum.katalon.com/u/porte.marvin)\
**Post date:** [May 4, 2020, 9:01am UTC](https://forum.katalon.com/t/changing-the-download-path-dynamically-during-runtime/20758/9 "2020-05-04T09:01:57Z")

</div>

Hi all,

For those who are asking what I did, There are basically 3 methods i created to simplify things.

#1 createDownloadFolder()  
#2 getCurrentBrowser()  
#3 changeDownloadPath(string path, string browser)

If you need only the changeDownloadPath, here is my code simple code snippet. We are only using chrome and firefox so my code is only for chrome and firefox. You can just basically add another elseif for other browsers.

@Keyword  
def changeDownloadPath(String browser, String path){

```
	if(browser=="chrome" || browser=="chrome-headless"){
		HashMap<String, Object> chromePrefs = new HashMap<String, Object>()

		chromePrefs.put("download.default_directory", path)
		chromePrefs.put("download.directory_upgrade", true)
		chromePrefs.put("browser.set_download_behavior", 'allow')
		chromePrefs.put("download.prompt_for_download", false)

		RunConfiguration.setWebDriverPreferencesProperty("prefs", chromePrefs)

	} else if(browser=="firefox" || browser=="firefox-headless"){

		HashMap<String, Object> profile = new HashMap<String, Object>()

		profile.put("browser.download.dir", path)
		profile.put("browser.download.folderList", 2)
		profile.put("browser.helperApps.neverAsk.saveToDisk", "application/vnd.openxmlformats-officedocument.wordprocessingml.document,	application/msword, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;application/vnd.ms-excel, application/vnd.ms-excel, application/pdf")
		profile.put("browser.download.manager.showWhenStarting",false);
		profile.put("pdfjs.disabled", true);

		RunConfiguration.setWebDriverPreferencesProperty("firefox_profile", profile)

	} else{
		KeywordUtil.logInfo("-- CHANGE DOWNLOAD PATH FAILED --")
	}
}

```

Hope this helps. 🙂

---

<div class="post-metadata">

**Author:** ![sivajothieswaran.sub](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@sivajothieswaran.sub](https://forum.katalon.com/u/sivajothieswaran.sub)\
**Post date:** [June 12, 2020, 4:07pm UTC](https://forum.katalon.com/t/changing-the-download-path-dynamically-during-runtime/20758/10 "2020-06-12T16:07:04Z")

</div>

Hi Marvin,

Keyword until was passed without any error, Didn’t download corresponding path.  
Can you please help on this issue

---

<div class="post-metadata">

**Author:** ![Nagesh.allu](https://avatars.discourse-cdn.com/v4/letter/n/d9b06d/32.png) [@Nagesh.allu](https://forum.katalon.com/u/Nagesh.allu)\
**Post date:** [January 13, 2021, 7:46pm UTC](https://forum.katalon.com/t/changing-the-download-path-dynamically-during-runtime/20758/11 "2021-01-13T19:46:59Z")

</div>

This setup is working for me .

GlobalVariable.DownloadPath=RunConfiguration.getReportFolder()+"\Download"  
println(‘GlobalVariable.DownloadPath:’+GlobalVariable.DownloadPath)  
File file = new File(GlobalVariable.DownloadPath)  
file.mkdir();  
GlobalVariable.DownloadPath =GlobalVariable.DownloadPath+"\"  
HashMap\<String, Object\> chromePrefs = new HashMap\<String, Object\>()  
chromePrefs.put(“download.default\_directory”, GlobalVariable.DownloadPath)  
chromePrefs.put(“download.directory\_upgrade”, true)  
chromePrefs.put(“browser.set\_download\_behavior”, ‘allow’)  
chromePrefs.put(“download.prompt\_for\_download”, false)  
RunConfiguration.setWebDriverPreferencesProperty(“prefs”, chromePrefs)

---

<div class="post-metadata">

**Author:** ![sasikanth.mirabana](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/sasikanth.mirabana/32/16103_2.png) [@sasikanth.mirabana](https://forum.katalon.com/u/sasikanth.mirabana)\
**Post date:** [June 15, 2021, 8:55am UTC](https://forum.katalon.com/t/changing-the-download-path-dynamically-during-runtime/20758/12 "2021-06-15T08:55:46Z")

</div>

It’s not working for me.  
I’m getting below error message.  
Reason:  
java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property;

Anyone please help me for this issue…

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![sasikanth.mirabana](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/sasikanth.mirabana/32/16103_2.png) [@sasikanth.mirabana](https://forum.katalon.com/u/sasikanth.mirabana)\
**Post date:** [June 21, 2021, 12:04pm UTC](https://forum.katalon.com/t/changing-the-download-path-dynamically-during-runtime/20758/13 "2021-06-21T12:04:08Z")

</div>

Hi Everyone  
I have resolved the issue

---

<div class="post-metadata">

**Author:** ![matthew.fischl](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/matthew.fischl/32/16104_2.png) [@matthew.fischl](https://forum.katalon.com/u/matthew.fischl)\
**Post date:** [August 24, 2021, 7:45pm UTC](https://forum.katalon.com/t/changing-the-download-path-dynamically-during-runtime/20758/14 "2021-08-24T19:45:30Z")

</div>

@porte.marvin. Same here. I can get this code to run without error, but subsequent downloads do not appear in the “path” location.
