Selenium Grid 2 – 远程Webdriver未在FireFox中设置用户代理首选项

我在Windows机器上使用selenium server 2.28。 我已经设置了集线器和节点。 我正在使用.net来编写我的测试用例。 我使用以下代码使用自定义FireFox(17.0.1)配置文件与用户代理更改(到iPhone)。

FirefoxProfileManager profileManager = new FirefoxProfileManager(); FirefoxProfile profile = profileManager.GetProfile(FireFox_Profile_Name); profile.SetPreference("general.useragent.override", _sUserAgent); DesiredCapabilities capability = DesiredCapabilities.Firefox(); capability.SetCapability(FirefoxDriver.ProfileCapabilityName, profile); 

我正在实例化一个这样的RemoteWebDriver实例:

 driver = new RemoteWebDriver(new Uri("hub_uri"), capability); 

当我在节点机器上检查firefox实例中的about:config时,我根本看不到general.useragent.override首选项。 如果我使用:

 driver = new FirefoxDriver(profile); 

首选项设置正确。 我错过了什么吗?

我正在尝试做一些非常类似的事情(设置Firefox使用Windows身份validation)。

在我的(有限的)实验中,只使用profile将使用本地驱动程序实例,但在与Selenium Server交谈时则不行。 我可以通过使用profile.ToBase64String()将配置文件传递给Selenium Server。

以下是使用Python在Grid 2中传递用户代理的方法。 如果您不想要代理,只需将其删除即可。

  myProxy = IP:PORT proxy = Proxy({ 'proxyType': ProxyType.MANUAL, 'httpProxy': myProxy, 'ftpProxy': myProxy, 'sslProxy': myProxy, 'noProxy': '' # set this value as desired }) desired_capabilities = webdriver.DesiredCapabilities.FIREFOX.copy() browser_profile = webdriver.FirefoxProfile() browser_profile.set_preference("general.useragent.override", 'USERAGENT' ) desired_capabilities["firefox_profile"] = browser_profile.update_preferences() driver = webdriver.Remote( command_executor='http://IPADDRESS:4444/wd/hub',desired_capabilities=desired_capabilities, browser_profile=browser_profile, proxy = proxy) 

希望有所帮助