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.
Asked: 2023-03-01 11:00:00 +0000
Seen: 10 times
Last updated: Oct 16 '22