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

醉酒当歌 提交于 2020-01-12 10:52:12

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!