download.default_directory selenium java 在 84 版本的 Chrome 驱动器中不起作用。

huangapple go评论80阅读模式
英文:

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&lt;String, Object&gt; prefs = new HashMap&lt;String, Object&gt;();
         
prefs.put(&quot;download.default_directory&quot;, &quot; path &quot;);

ChromeOptions options = new ChromeOptions();
options.setExperimentalOption(&quot;prefs&quot;, 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(&quot;chrome://settings/downloads&quot;);

// add some operation that change the default download directory

huangapple
  • 本文由 发表于 2020年8月14日 01:41:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/63400513.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定