本文介绍了如何在使用Chromedriver启动时在Chrome中下载设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Chrome的设置中选中了在下载前询问每个文件的保存位置选项。但每次我使用Chromedriver打开Chrome时,都会因为文件被保存到默认下载位置而被取消选中。
I have checked the option to "Ask where to save each file before downloading" in settings of my Chrome. But each time I am opening the Chrome using Chromedriver it is getting unchecked due to which the files are getting saved to the default download location.
我该怎么做才能让选项不会在我使用Chromedriver启动Chrome时被取消选中?
What can I do so that the option does not get unchecked when I launch Chrome using Chromedriver?
我使用以下代码块使用chromedriver启动chrome:
I am using the following code block to launch chrome using chromedriver:
public static IWebDriver driver_chrome;
driver_chrome = new ChromeDriver();
/*Added for setting timeouts for other browser*/
driver_chrome.Manage().Timeouts().SetPageLoadTimeout(new TimeSpan(0, 2, 0));
driver_chrome.Navigate().GoToUrl("http://www.google.co.in");
if (driver_chrome.WindowHandles.Count >= 1)
{
driverTemp = driver_chrome;
}
推荐答案
使用以下代码片段:
var options = new ChromeOptions(); options.AddUserProfilePreference("download.prompt_for_download", true); driver_chrome = new ChromeDriver(options);
driver_chrome.Manage().Timeouts().SetPageLoadTimeout(new TimeSpan(0, 2, 0));
driver_chrome.Navigate().GoToUrl("http://www.google.co.in");
这篇关于如何在使用Chromedriver启动时在Chrome中下载设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!