How to make the settings for Download in Chrome wh

2019-04-02 06:48发布

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条回答
Melony?
2楼-- · 2019-04-02 07:35

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");
查看更多
登录 后发表回答