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

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


If you have updated to Chrome Version 36.0.x and Selenium 2.42, Martins solution no longer works.

It seems to have been updated. You now can use the following code

ChromeOptions options = new ChromeOptions();options.AddUserProfilePreference(string preferenceName, object preferenceValue); 

I currently use it to change my Printer settings to "Save as PDF" instead of the default using this code as an example

ChromeOptions options = new ChromeOptions();options.AddUserProfilePreference("printing.print_preview_sticky_settings.appState", "{\"version\":2,\"isGcpPromoDismissed\":false,\"selectedDestinationId\":\"Save as PDF\");

I thought Martin's solution was very good and accurate, but it suddenly stopped working for me, so naturally I had to see if I could find a solution.


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<string,object> prefs { get; set; }}public static void Initialize(){    var options = new ChromeOptionsWithPrefs();    options.prefs = new Dictionary<string, object>    {        { "intl.accept_languages", "nl" }    };    _driver = new ChromeDriver(@"C:\path\chromedriver", options);}