You can't directly change the RemoteWebDriver
. RemoteWebDriver c# Documentation. From the documentation, you can see that the RemoteWebDriver is an abstraction of more concrete implementations like FirefoxDriver
and ChromeDriver
.
These imlementations expose preferences like the user.agent
. What the api is trying to tell you, is that not all RemoteWebDrivers
need to have preferences and thus it's not part of the class.
You can however do the following since FirefoxDriver extends RemoteWebDriver
RemoteWebDriver driver = new FirefoxDriver(profile);
You can use the FirefoxProfile
and a FirefoxDriver
FirefoxProfile profile = new FirefoxProfile();
profile.SetPreference("general.useragent.override", "Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5355d Safari/8536.25");
IWebDriver driver = new FirefoxDriver(profile);
A full example:
public static IWebDriver GetDriver(string driver, Devices device)
{
DeviceModel model = Device.Get(device);
IWebDriver webDriver;
switch (driver.ToLower())
{
case "safari":
webDriver = new SafariDriver();
break;
case "chrome":
webDriver = new ChromeDriver();
break;
case "ie":
webDriver = new InternetExplorerDriver();
break;
//case "firefox":
default:
var profile = new FirefoxProfile();
profile.SetPreference("general.useragent.override", model.UserAgent);
webDriver = new FirefoxDriver(profile);
webDriver.Manage().Window.Size = model.ScreenSize;
break;
}
return webDriver;
}