Setting user-agent for remote chromedriver in Selenium

Harald Schult Ulriksen

Setting the user-agent in .net is not straight forward. Using the chrome webdriver directly this can be done using chromeoptions

var ios6ua = "Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25"

var chromeOptions = new ChromeOptions();
chromeOptions.AddArgument("--user-agent=" + ios6ua);

Instance = new ChromeDriver(chromeOptions);

Now, as the remote driver does not accept chrome options, this must be sett using capabilites and passed to the remote driver.

var dictionary = new Dictionary 
    {"args", new List { "--user-agent=" + ios6ua}}

var caps = DesiredCapabilities.Chrome(); 

Instance = new RemoteWebDriver(new Uri("http://localhost:9515"),caps);

Just remember to change the uri for your remote webdriver.

A list of chrome arguments can be found here