19

This is my solution, based on this question

But it's not working, I need to change the default download directory for google chrome to

C:\temp\

Thanks for the 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);
    }
}

I found 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);
}
spaleet
  • 838
  • 2
  • 10
  • 23
LamND7
  • 191
  • 1
  • 1
  • 14

4 Answers4

23

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);
}
ProgrammingLlama
  • 36,677
  • 7
  • 67
  • 86
Adarsha
  • 2,267
  • 22
  • 29
11

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);
fiat
  • 15,501
  • 9
  • 81
  • 103
1

I know it's not best, may be even not good way to to it, but maybe will help if you didn't find other answers helpful. It works for me:

private static ChromeOptions options()
{
    ChromeOptions chromeOptions = new ChromeOptions();
    chromeOptions.AddUserProfilePreference("download.default_directory", @"path");
    chromeOptions.AddUserProfilePreference("download.prompt_for_download", false);

    return chromeOptions;
    }
     
protected static IWebDriver driver = new ChromeDriver(options());
Daria
  • 11
  • 2
1

Works fine for me:

ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.AddUserProfilePreference("download.default_directory", @"path");
chromeOptions.AddUserProfilePreference("download.prompt_for_download", false);

thanks