Selenium Grid 2 - Remote webdriver not setting the user agent preference in FireFox

余生长醉 提交于 2019-12-23 05:04:38

问题


I am using selenium server 2.28 on windows machine. I have set up the hub and node. I am using .net to write my test cases. I am using the following code to use custom FireFox (17.0.1) Profile with the user agent changed(to 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);

And I am instantiating a RemoteWebDriver instance like this:

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

When I check the about:config in the instance of firefox on the node machine, I don't see the general.useragent.override preference at all. If i use:

driver = new FirefoxDriver(profile); 

The preference is set correctly. Am I missing something?


回答1:


I am trying to do something very similar at the moment (setting Firefox to use Windows authentication).

In my (somewhat limited) experimentation to make this work, using just profile will work with a local driver instance, but not when talking to Selenium Server. I can get the profile to be passed to Selenium Server by using profile.ToBase64String() as hinted to here.




回答2:


Here's how to pass the user agent in Grid 2 using Python. If you don't want the proxy, just remove it.

    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) 

Hope that helps



来源:https://stackoverflow.com/questions/14204334/selenium-grid-2-remote-webdriver-not-setting-the-user-agent-preference-in-fire

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!