How to set Chrome preferences using Selenium Webdriver .NET binding?

后端 未结 2 1088
暗喜
暗喜 2020-11-30 07:47

Here is what I\'m using, user agent can be successfully set, while download preferences cannot.

Windows 7, Chrome 26, Selenium-dotnet-2.31.2, chromedriver_win_26.0.1

2条回答
  •  感情败类
    2020-11-30 08:38

    The Selenium dotNet driver does not support setting the chrome.prefs out of the box. The problem is that chrome.prefs must be defined as prefs under the chromeOptions node. The ChromeOptions class does not contain this variable, so you'll need to create your own ChromeOptions class:

    public class ChromeOptionsWithPrefs: ChromeOptions
    {
        public Dictionary prefs { get; set; }
    }
    
    public static void Initialize()
    {
        var options = new ChromeOptionsWithPrefs();
        options.prefs = new Dictionary
        {
            { "intl.accept_languages", "nl" }
        };
        _driver = new ChromeDriver(@"C:\path\chromedriver", options);
    }
    

提交回复
热议问题