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


here i'm using, user agent can set, while download preferences cannot.

windows 7, chrome 26, selenium-dotnet-2.31.2, chromedriver_win_26.0.1383.0

chromeoptions chromeoptions = new chromeoptions(); var prefs = new dictionary<string, object> {     { "download.default_directory", @"c:\code" },     { "download.prompt_for_download", false } }; chromeoptions.addadditionalcapability("chrome.prefs", prefs); chromeoptions.addargument("--user-agent=" + "some safari agent"); var driver = new chromedriver(chromeoptions); 

taken chromedriver.log:

[1.201][fine]:      initializing session capabilities {     "browsername": "chrome",     "chrome.prefs": {        "download.default_directory": "c:\\code",        "download.prompt_for_download": false     },     "chrome.switches": [ "--user-agent=mozilla/5.0 (windows nt 6.1; wow64) applewebkit/534.57.2 (khtml, gecko) version..." ],     "chromeoptions": {        "args": [ "--user-agent=mozilla/5.0 (windows nt 6.1; wow64) applewebkit/534.57.2 (khtml, gecko) version..." ],        "binary": "",        "extensions": [  ]     },     "javascriptenabled": true,     "platform": "windows",     "version": ""  } 

check temp preferences file @ *temp\google\chrome\user data\default\preferences, no "default_directory" , "prompt_for_download" set.

   "download": {       "directory_upgrade": true    }, 

the selenium dotnet driver not support setting chrome.prefs out of box. problem chrome.prefs must defined prefs under chromeoptions node. chromeoptions class not contain variable, you'll need create 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); } 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -