Selenium 2 - Setting user agent for IE and Chrome

Viewed 12964

I need to change the user agent value in IE and Chrome for some of our tests. The only selenium 2 examples I've come across only work with FirefoxDriver.

Has anyone managed to change the user agent for IE and Chrome?

Mark

4 Answers

I finally found out how to do that at least in chrome:

capabilities = webdriver.common.desired_capabilities.DesiredCapabilities.CHROME.copy()
capabilities['javascriptEnabled'] = True
options = webdriver.ChromeOptions()
options.add_argument('--user-agent=<YOUR USER AGENT HERE>')

driver = webdriver.Remote(command_executor='http://<YOUR SELENIUM HUB HERE>:4444/wd/hub',desired_capabilities=capabilities, options=options)

Sources: https://gist.github.com/thureos/2db0bc44589669a00c22a86503c80bbb https://seleniumhq.github.io/selenium/docs/api/py/webdriver_remote/selenium.webdriver.remote.webdriver.html?highlight=remote

Related