How to change selenium user agent in selenium-webdriver nodejs land?
Problem
I'm in javascript + mocha + node land.
I have tried setting Useragent and 'user-agent' as keys on capabilities:
var webdriver = require('selenium-webdriver');
var ua = 'Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X)';
var driver = new webdriver.Builder().
...
withCapabilities({ 'browserName': 'firefox',
userAgent: ua,
'user-agent': ua,
}).
build();
There is this answer which says to use a firefox profile, but that's not exposed. There is no driver.FirefoxProfile
nor one exposed globally nor webdriver.FirefoxProfile
nor driver.profiles
etc.
I have tried Googling and looking the source and the documentation but there is nothing on this.
Problem courtesy of: Andy Ray
Solution
You cannot do it with Firefox, but you can do it with Chrome. It's undocumented:
var chrome = require('selenium-webdriver/chrome');
var opts = new chrome.Options();
opts.addArguments(['user-agent="YOUR_USER_AGENT"']);
var driver = new webdriver.Builder().
withCapabilities(opts.toCapabilities()).
build();
Solution courtesy of: Andy Ray
Discussion
View additional discussion.