允许ChromeDriver中的多个下载

时间:2017-06-22 18:03:25

标签: c# google-chrome selenium selenium-webdriver selenium-chromedriver

我需要使用ChromeDriver(C#)在Chrome中下载多个文件,第一个文件已成功下载,但其他人没有下载,出现了一个窗口询问"下载多个文件 - 允许|阻止"

我需要配置为自动下载。在Chrome的偏好设置中有此选项"设置 - >内容设置 - >自动下载 - >允许所有网站自动下载多个文件"

我需要配置" ChromeOptions"比如示例

var options = new ChromeOptions();
options.AddUserProfilePreference("...", true);

以下是带有Chrome消息的图片

Window of Chrome message

2 个答案:

答案 0 :(得分:11)

我找到了解决方案。只需添加首选项:

var options = new ChromeOptions();
options.AddUserProfilePreference("profile.default_content_setting_values.automatic_downloads", 1);

答案 1 :(得分:0)

我将此添加到我的首选项列表中。 alexandre 提供的设置名称有所帮助。现在它起作用了!

currentDIR = os.getcwd()
chromeOptions = webdriver.ChromeOptions()
prefs = {"download.default_directory" : currentDIR, "profile.default_content_setting_values.automatic_downloads":1}
chromeOptions.add_experimental_option("prefs",prefs)
chromedriver = currentDIR + '\\chromedriver_win32\\chromedriver.exe'
browser = webdriver.Chrome(executable_path=chromedriver, options=chromeOptions)