C# Selenium Grid 2-远程webdriver未在FireFox中设置用户代理首选项
我正在windows计算机上使用selenium server 2.28。我已经设置了中心和节点。我正在使用.net编写测试用例。我使用下面的代码使用自定义FireFox(17.0.1)配置文件,并将用户代理更改为iPhone 我正在实例化一个C# Selenium Grid 2-远程webdriver未在FireFox中设置用户代理首选项,c#,firefox,selenium,preference,C#,Firefox,Selenium,Preference,我正在windows计算机上使用selenium server 2.28。我已经设置了中心和节点。我正在使用.net编写测试用例。我使用下面的代码使用自定义FireFox(17.0.1)配置文件,并将用户代理更改为iPhone 我正在实例化一个RemoteWebDriver实例,如下所示: driver = new RemoteWebDriver(new Uri("hub_uri"), capability); 当我在节点机器上的firefox实例中检查about:config时,我根本看不到
RemoteWebDriver
实例,如下所示:
driver = new RemoteWebDriver(new Uri("hub_uri"), capability);
当我在节点机器上的firefox实例中检查about:config
时,我根本看不到general.useragent.override首选项。如果我使用:
driver = new FirefoxDriver(profile);
首选项设置正确。我遗漏了什么吗?我正在尝试做一些非常类似的事情(将Firefox设置为使用Windows身份验证)
在我的(有限的)实验中,仅使用
profile
就可以使用本地驱动程序实例,但与Selenium服务器对话时就不行了。我可以使用profile.ToBase64String()
获得要传递给Selenium服务器的配置文件,正如所暗示的那样。下面是如何使用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)
希望对您有所帮助您是否也尝试过从webdriver实例化的浏览器查看whatsmyuseragent.com上的useragent值?只是为了确保..?A.J,我刚刚检查了一下,用户代理没有改变。谢谢@jheppinstall的帮助(虽然不是完全有效)。当我使用现有配置文件并使用
ToBase64String()
传递它时,我在grid hubjava.util.zip.ZipException上得到一个错误:无效的条目大小(预期…但得到…
。我创建了一个新配置文件,然后在使用`ToBase64String()转换它之前对配置文件的首选项进行了更改’。这样我就可以将配置文件传递到节点。
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)