【问题标题】:Selenium Grid 2 - Remote webdriver not setting the user agent preference in FireFoxSelenium Grid 2 - 远程 webdriver 未在 FireFox 中设置用户代理首选项
【发布时间】:2013-01-07 21:28:08
【问题描述】:

我在 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); 

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

【问题讨论】:

  • 您是否也尝试从 webdriver 实例化的浏览器中查看 whatsmyuseragent.com 上的 useragent 值?只是为了确保..?
  • A.J,我刚刚检查了,用户代理没有改变。

标签: c# firefox selenium preference


【解决方案1】:

我目前正在尝试做一些非常相似的事情(将 Firefox 设置为使用 Windows 身份验证)。

在我的(有些有限的)实验中,仅使用profile 将与本地驱动程序实例一起使用,但在与 Selenium Server 通信时则不行。我可以使用 profile.ToBase64String() 将配置文件传递给 Selenium Server,正如 here 所暗示的那样。

【讨论】:

  • 感谢@jheppinstall 有效(尽管不完全)。当我使用现有配置文件并使用ToBase64String() 传递它时,我在网格集线器java.util.zip.ZipException: invalid entry size (expected... but got... 上收到错误消息。我创建了一个新的配置文件,然后在使用“ToBase64String()”进行转换之前更改了配置文件的首选项。这样我就能够将配置文件传递给节点。
【解决方案2】:

以下是使用 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) 

希望有帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-03-31
    • 2012-10-01
    • 2015-07-29
    • 2016-11-08
    • 2019-08-07
    • 2017-05-29
    • 2015-12-31
    相关资源
    最近更新 更多