Alex
Alex

Reputation: 347

Powershell : set download directory in chrome - selenium

I'm trying to change the default path for chrome downloads with selenium on powershell:

$savepath="path"
$ChromeOptions = New-Object OpenQA.Selenium.Chrome.ChromeOptions
$chromePrefs=@{"download.default_directory" = $savepath}
$ChromeOptions.AddAdditionalCapability("prefs",$chromePrefs)
$driver = New-Object OpenQA.Selenium.Chrome.ChromeDriver($ChromeOptions)

But here is the error I get :

Exception calling "AddAdditionalCapability" with "2" argument(s): "There is already an option for the prefs capability. Please use the instead. Parameter name: capabilityName"

Thanks !

Upvotes: 1

Views: 1535

Answers (1)

Paulo Souza
Paulo Souza

Reputation: 36

The correct way that worked for me:

$myMap = @{}
$myMap.Add("default_directory", "c:\temp")
$myMap.Add("prompt_for_download", $true)

$ChromeOptions.AddUserProfilePreference("download", $myMap)

Upvotes: 2

Related Questions