Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To establish a default download folder using Chrome Capabilities in Selenium, you can use the following code snippet:

Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("download.default_directory", "path/to/download/folder");
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", prefs);

WebDriver driver = new ChromeDriver(options);

In this code, we first create a Map object called prefs, which contains a key-value pair to specify the default download folder. We then create a ChromeOptions object and set the prefs option using the setExperimentalOption() method. Finally, we create a ChromeDriver instance with the options object.

The download.default_directory preference sets the default download directory for Chrome. You can replace path/to/download/folder with the actual file path of the folder where you want downloads to be saved.

Note that this approach only works for Chrome browsers. If you want to set a default download folder for Firefox or other browsers, you'll need to use a different set of capabilities.