英文:
download.default_directory selenium java not working in 84 chrome driver
问题
无法在Selenium Java中更改默认的Chrome驱动程序下载路径。
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("download.default_directory", "路径");
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", prefs);
ChromeDriver driver = new ChromeDriver(options);
英文:
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
得分: 2
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
英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论