Can someone pls tell me how to switch the user agent using webdriver in Java? I tried below, but getting errors.
FirefoxProfile ffp = new FirefoxProfile();
ffp.setPreference("general.useragent.override",
"Mozilla/5.0 (Windows NT 6.1; rv:15.0) Gecko/20100101 Firefox/15.0");
WebDriver fd = new FirefoxDriver(ffp);
I believe this solution is the desired answer to the question. I tested it and it worked for me. Happy coding!
I needed to do it for Chrome, and needed to set a specific string (not fitting as platform, browser or version) for Googlebot.
DesiredCapabilities would help you to change user agent.
You can achieve this by calling these methods:
setBrowserName(java.lang.String browserName)
setPlatform(Platform platform)
setVersion(java.lang.String version)
Or
static DesiredCapabilities chrome()
static DesiredCapabilities firefox()
static DesiredCapabilities iphone()
More here.