Setting User Agent String with Selenium

5,906 views
Skip to first unread message

Aniket Gadre

unread,
Feb 14, 2012, 10:21:38 AM2/14/12
to seleniu...@googlegroups.com, webd...@googlegroups.com
Hi All,
Is it possible to set the user agent string (in my case for ipad) in browser with selenium?

Best Regards,
Aniket

David

unread,
Feb 14, 2012, 12:32:44 PM2/14/12
to webdriver
Good question, I'd like to know too. But why the case for iPad? I
guess you can only simulate browsing as another browser via user agent
string, but you have no option to specify iPad browser via Selenium
(mobile Safari vs Opera, etc.) unlike desktop browsers.

mari muthu

unread,
Feb 15, 2012, 6:10:36 AM2/15/12
to webdriver
Hi,

FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("general.useragent.override", "iPhone");
WebDriver driver = new FirefoxDriver(profile);

Thanks & Regards,
M.Marimuthu

Krishnan Mahadevan

unread,
Feb 15, 2012, 6:14:20 AM2/15/12
to webd...@googlegroups.com
Marimuthu,
How would you make use of FirefoxDriver and have it run against the selenium server instance running on an iPhone ?
I thought the only way to interact with an iPhone or Android environment was to use their respect WebDrivers or resort to RemoteWebDriver and couple it with the corresponding DesiredCapabilities object.



Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"


--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To post to this group, send email to webd...@googlegroups.com.
To unsubscribe from this group, send email to webdriver+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/webdriver?hl=en.


David

unread,
Feb 15, 2012, 1:38:45 PM2/15/12
to webdriver
Agree with Krishnan, Marimuthu's approach can set user agent string,
faking the browser to the website/server, but it will of course
actually be using the wrong browser/WebDriver. It would be same as
using HTTP request libraries and setting HTTP request header
specifying user agent string to the website/server.

But this also brings back my original question, why even bother
setting user agent string for a mobile browser? Unless you are testing
from desktop and faking as mobile browser. Or unless you want to test
unsupported mobile browser by faking as it (e.g. Opera Mobile/Mini vs
WebDriver's iPhone/iPad driver which is for mobile Safari).

On Feb 15, 3:14 am, Krishnan Mahadevan

Automation User

unread,
May 5, 2012, 1:13:48 AM5/5/12
to webd...@googlegroups.com, seleniu...@googlegroups.com
We can switch user agent in FF 

FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("general.useragent.override", "Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3");

WebDriver driver = new FirefoxDriver(profile);

Reply all
Reply to author
Forward
0 new messages