Description
The UserAgent
property returns the user agent string of the given mobile browser profile (specified by the VirtualBrowserInfoObj object). The user agent string identifies the browser to web servers so that they can return browser-specific content if needed.
The user agent strings of all mobile browser profiles that can be used in a test project are specified in the project’s Open Applications | Web | Virtual Browsers properties.
Declaration
VirtualBrowserInfoObj.UserAgent
Read-Only Property | String |
VirtualBrowserInfoObj | An expression, variable or parameter that specifies a reference to a VirtualBrowserInfo object |
Applies To
The property is applied to the following object:
Property Value
The user agent string of a mobile browser. For example, the user agent string of the iPhone 7 browser emulator is as follows:
Mozilla/5.0 (iPhone; CPU iPhone OS 10_0 like Mac OS X) AppleWebKit/602.1.38 (KHTML, like Gecko) Version/10.0 Mobile/14A5297c Safari/602.1
You can find more user agent examples here:
http://www.zytrax.com/tech/web/mobile_ids.html
https://udger.com/resources/ua-list#Mobile Browser
Example
The following example logs the user agent of the iPad browser emulator:
JavaScript, JScript
function Test()
{
var uastr = VirtualBrowsers.Item("Apple iPad").UserAgent;
Log.Message("iPad user agent: " + uastr);
}
Python
def Test():
uastr = VirtualBrowsers.Item["Apple iPad"].UserAgent;
Log.Message("iPad user agent: " + uastr);
VBScript
Sub Test
Dim uastr
uastr = VirtualBrowsers.Item("Apple iPad").UserAgent
Log.Message "iPad user agent: " & uastr
End Sub
DelphiScript
procedure Test;
var uastr;
begin
uastr := VirtualBrowsers.Item('Apple iPad').UserAgent;
Log.Message('iPad user agent: ' + uastr);
end;
C++Script, C#Script
function Test()
{
var uastr = VirtualBrowsers["Item"]("Apple iPad")["UserAgent"];
Log["Message"]("iPad user agent: " + uastr);
}
See Also
Testing Mobile Web Applications Using Emulator
VirtualBrowserInfo Object
ScreenHeight Property
ScreenWidth Property
DevicePixelRatio Property
Name Property
RunOptions Property