Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Set default download directory chrome WebDriver?

This is my solution, i'm reference at: How to set Chrome preferences using Selenium Webdriver .NET binding?

But not working, i need change default download directory for google chrome to

C:\temp\

Thanks for help.

public class ChromeOptionsWithPrefs : ChromeOptions
    {
        public Dictionary<string, object> prefs { get; set; }
    }

public static void Initialize()
    {
        var options = new ChromeOptionsWithPrefs
        {
            prefs = new Dictionary<string, object>
            {
                {"download.default_directory", @"C:\temp\"}
            }
        };
        RemoteWebDriver driver = new ChromeDriver(@"D:\chromedriver_win32\", options);
        var download = driver.FindElements(By.XPath("//a[.='Download']"));
        foreach (var t in download)
        {
            t.SendKeys(Keys.Enter);
        }
    }

Im finded this solution, it worked

var chromeOptions = new ChromeOptions();
        chromeOptions.AddUserProfilePreference("download.default_directory", @"D:\DataTest");
        chromeOptions.AddUserProfilePreference("intl.accept_languages", "nl");
        chromeOptions.AddUserProfilePreference("disable-popup-blocking", "true");
        var driver = new ChromeDriver(@"D:\chromedriver_win32\", chromeOptions);
        var download = driver.FindElements(By.XPath("//a[.='ダウンロード']"));
        foreach (var t in download)
        {
            t.SendKeys(Keys.Enter);

        }
like image 495
LamND7 Avatar asked Feb 17 '16 02:02

LamND7


2 Answers

Just pasting the answer that OP found, but did not add as an answer.

var chromeOptions = new ChromeOptions();
chromeOptions.AddUserProfilePreference("download.default_directory", @"D:\DataTest");
chromeOptions.AddUserProfilePreference("intl.accept_languages", "nl");
chromeOptions.AddUserProfilePreference("disable-popup-blocking", "true");
var driver = new ChromeDriver(@"D:\chromedriver_win32\", chromeOptions);
var download = driver.FindElements(By.XPath("//a[.='ダウンロード']"));

foreach (var t in download)
{
    t.SendKeys(Keys.Enter);
}
like image 142
Adarsha Avatar answered Sep 18 '22 01:09

Adarsha


These settings worked for me

var chromeOptions = new ChromeOptions();
var downloadDirectory = "C:\Temp";

chromeOptions.AddUserProfilePreference("download.default_directory", downloadDirectory);
chromeOptions.AddUserProfilePreference("download.prompt_for_download", false);
chromeOptions.AddUserProfilePreference("disable-popup-blocking", "true");

var driver =  new ChromeDriver(chromeOptions);
like image 20
fiat Avatar answered Sep 21 '22 01:09

fiat