使用 Chrome 驱动程序启动时,如何在 Chrome 中进行下载设置?

How to make the settings for Download in Chrome when launched using Chromedriver?

我已经在 Chrome 的设置中选中 "Ask where to save each file before downloading" 选项。但是每次我使用 Chrome 驱动程序打开 Chrome 时,由于文件被保存到默认下载位置,它会被取消选中。

我该怎么做才能在使用 Chrome 驱动程序启动 Chrome 时取消选中该选项?

我正在使用以下代码块启动 chrome 使用 chrome 驱动程序:

            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");