download.default_directory selenium java not working in 84 chrome driver

Viewed 3144

I am not able to change the default chrome driver download path in selenium java.

Map<String, Object> prefs = new HashMap<String, Object>();
         
prefs.put("download.default_directory", " path ");

ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", prefs);

ChromeDriver driver= new ChromeDriver(options);
1 Answers

Your code is great and meets the official manual.

I think the problem is with path parameter.

The following come from the chromedriver official manual:

However, there are several caveats to be aware of:

  1. Chrome disallows using certain directories for download. In particular, you cannot use the desktop folder as the download directory. On Linux, you also cannot use the home directory for download. Since the exact list of forbidden directories is subject to change, it is recommended that you use a directory that has no special meaning to the system.
  2. ChromeDriver does not automatically wait for download to complete. If you call driver.quit() too soon, Chrome might terminate before the download has finished.
  3. Relative paths do not always work. For best result, use full path instead.
  4. On Windows, Use "\" as path separators. Using "/" is not reliable on Windows.

IF the manual does not work for you, try this one that works but isn't smart:

WebDriver driver = new ChromeDriver();
driver.get("chrome://settings/downloads");

// add some operation that change the default download directory
Related