我尝试了所有内容来更改Chrome的默认下载路径,但无效。
我正在使用.Net Core 2.0 C#
<PackageReference Include="Selenium.Chrome.WebDriver" Version="2.30.0" />
<PackageReference Include="Selenium.Firefox.WebDriver" Version="0.17.0" />
<PackageReference Include="Selenium.Support" Version="3.6.0" />
<PackageReference Include="Selenium.WebDriver" Version="3.6.0" />
<PackageReference Include="Selenium.WebDriver.ChromeDriver" Version="2.33.0" />
<PackageReference Include="Selenium.WebDriver.MicrosoftDriver" Version="15.15063.0" />
string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var chromeOptions = new ChromeOptions();
chromeOptions.AddUserProfilePreference("download.default_directory", path);
chromeOptions.AddUserProfilePreference("intl.accept_languages", "nl");
chromeOptions.AddUserProfilePreference("disable-popup-blocking", "true");
var driver = new ChromeDriver(path, chromeOptions);
我也尝试过使用prefs的类,但也没有用。
谢谢!
答案 0 :(得分:4)
升级到chrome webdriver 2.30时遇到类似问题,在我的情况下,默认下载目录不再考虑在内。 尝试将其升级到(当前)最新的2.33,在这两个版本之间修复(https://sites.google.com/a/chromium.org/chromedriver/downloads)
这是我的代码示例:
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.AddUserProfilePreference("download.prompt_for_download", false);
chromeOptions.AddUserProfilePreference("download.directory_upgrade", true);
chromeOptions.AddUserProfilePreference("download.default_directory", Configuration.ResourcesPath);
Nuget包Selenium.WebDriver.ChromeDriver是最新的(https://www.nuget.org/packages/Selenium.WebDriver.ChromeDriver/)