【发布时间】:2016-05-28 13:52:42
【问题描述】:
这是我的解决方案,我参考: How to set Chrome preferences using Selenium Webdriver .NET binding?
但不起作用,我需要将谷歌浏览器的默认下载目录更改为
C:\temp\
感谢您的帮助。
public class ChromeOptionsWithPrefs : ChromeOptions
{
public Dictionary<string, object> prefs { get; set; }
}
public static void Initialize()
{
var options = new ChromeOptionsWithPrefs
{
prefs = new Dictionary<string, object>
{
{"download.default_directory", @"C:\temp\"}
}
};
RemoteWebDriver driver = new ChromeDriver(@"D:\chromedriver_win32\", options);
var download = driver.FindElements(By.XPath("//a[.='Download']"));
foreach (var t in download)
{
t.SendKeys(Keys.Enter);
}
}
我找到了这个解决方案,它有效
var chromeOptions = new ChromeOptions();
chromeOptions.AddUserProfilePreference("download.default_directory", @"D:\DataTest");
chromeOptions.AddUserProfilePreference("intl.accept_languages", "nl");
chromeOptions.AddUserProfilePreference("disable-popup-blocking", "true");
var driver = new ChromeDriver(@"D:\chromedriver_win32\", chromeOptions);
var download = driver.FindElements(By.XPath("//a[.='ダウンロード']"));
foreach (var t in download)
{
t.SendKeys(Keys.Enter);
}
【问题讨论】:
-
您没有在问题中给出答案。只需将其添加为答案..
标签: c# google-chrome selenium selenium-webdriver