0

Trying to use the code below to download a file at an exact location every time. It just downloads to the default downloads folder. Are there any other chrome options that will solve this issue?

ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.AddUserProfilePreference("download.prompt_for_download", false);
chromeOptions.AddUserProfilePreference("download.directory_upgrade", true);
chromeOptions.AddUserProfilePreference("download.default_directory", MyLocation);
driver = new ChromeDriver(service, chromeOptions);
  • 1
    Possible duplicate of [How to download CSV file through Firefox Profile in Java](https://stackoverflow.com/questions/44074656/how-to-download-csv-file-through-firefox-profile-in-java) – undetected Selenium Mar 22 '18 at 14:12
  • When this happened to me it was because the directory I set didn't actually exist on disk yet. Are you sure the directory exists? It won't automatically create it for you. You have to make sure it exists before the download happens. – tehbeardedone Mar 22 '18 at 14:25
  • The Directory is created dynamically, but it does exist before the scripts run. – Amit Brahmbhatt Mar 22 '18 at 18:27

1 Answers1

2

Adding these Arguments helped changing folder. Thanks, DebanjanB for pointing in the right direction - just that I needed Chrome/C# equivalent of your answer to the question.

                chromeOptions.AddArguments("--browser.download.folderList=2");
                chromeOptions.AddArguments("--browser.helperApps.neverAsk.saveToDisk=image/jpg");
                chromeOptions.AddArguments("--browser.download.dir="+MyLocation);
                chromeOptions.AddUserProfilePreference("download.default_directory", MyLocation);