问题
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.
What can I do so that the option does not get unchecked when I launch Chrome using Chromedriver?
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;
}
回答1:
I was able to achieve this using the following code snippet:
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");
来源:https://stackoverflow.com/questions/27896568/how-to-make-the-settings-for-download-in-chrome-when-launched-using-chromedriver