Browsers.Item Property

Applies to TestComplete 15.20, last modified on January 19, 2022

Description

Use this property to obtain information about a particular browser installed on the current computer.

Note: To get access to a web browser running on a remote computer or remote mobile device, use the Browsers.RemoteItem property.

Declaration

Browsers.Item(Index, Version, Platform)

Read-Only Property A BrowserInfo object
Index [in]    Required    Variant    
Version [in]    Optional    String Default value: Empty string   
Platform [in]    Optional    Integer Default value: pAny   

Applies To

The property is applied to the following object:

Parameters

The property has the following parameters:

Index

Specifies the browser instance you want to get. A browser can be specified via built-in constant, by the process name or by index within the collection:

Browsers.Item(btIExplorer).Run()
Browsers.Item("firefox").Run()
Browsers.Item(0).Run()

When specifying a browser via constant, the following values are acceptable:

Constant Value Description
btIExplorer -1 Microsoft Internet Explorer.
btFirefox -2 Mozilla Firefox.
btChrome -3 Google Chrome.
btEdge -6 Microsoft Edge.

When specifying a browser by its process name, the following values are acceptable: "firefox", "iexplore", "edge", and "chrome". The process names coincide with the values of ProcessName property of the respective Browser process.

When specifying a browser by its collection index, keep in mind that the first item in the collection has index 0, the second - 1, and so on. The total number of items in the collection is specified by the Browsers.Count property.

Version

A string that specifies the version of a browser instance to be obtained. The string may contain various combinations of digits and separator character. For example, all the following strings are valid values for the Version parameter: "3", "16.", "3.6.", "3.6.28", "9.0.8112.16421".

Platform

An integer indicating the platform of a browser instance to be obtained. Can have one of the following values:

Constant Value Description
pX86 0 A 32-bit version of the browser executable.
pX64 1 A 64-bit version of the browser executable.
pAny -1 Any available version of the browser executable.

If you have both 32- and 64-bit versions, the 32-bit version will be used.

If you specify a value for the Platform parameter, you will have to specify values for all three parameters. If the Version parameter is not important for you, you can specify an empty string as its value.

Property Value

A BrowserInfo object that provides scripting interface to the desired browser instance. If the Browsers collection does not contain an object with the specified index, name, version or platform TestComplete posts an error message to the test log.

Remarks

If your tests uninstall or install browsers during the run, call the Browsers.Refresh method to update the Browsers collection after the installation or uninstallation is over. This should be done before you continue working with the browsers.

Example

The following routine uses the properties and methods of Browsers and BrowserInfo objects to list all installed and supported browsers.

JavaScript, JScript

function ListBrowsers()
{
  var browser;
  
  for (var i=0; i < Browsers.Count; i++)
  {
    browser = Browsers.Item(i);
    Log.Message("Browser " + aqConvert.IntToStr(i) + " : " + browser.Description);
  }
}

Python

def ListBrowsers():
  for i in range (0, Browsers.Count-1):
    browser = Browsers.Item(i); 
    Log.Message("Browser " + aqConvert.IntToStr(i) + " : " + browser.Description);

VBScript

Sub ListBrowsers
  Dim browser
 
  For i = 0 To Browsers.Count-1
    Set browser = Browsers.Item(i)
    Log.Message("Browser " + aqConvert.IntToStr(i) + " : " + browser.Description)
  Next
End Sub

DelphiScript

procedure ListBrowsers;
var
  browser, i : OleVariant;
begin
  for i:=0 to Browsers.Count-1 do 
  begin
    browser := Browsers.Item(i);
    Log.Message('Browser ' + aqConvert.IntToStr(i) + ' : ' + browser.Description);
  end;
end;

C++Script, C#Script

function ListBrowsers()
{
  var browser;
  
  for (var i=0; i < Browsers["Count"]; i++)
  {
    browser = Browsers["Item"](i);
    Log["Message"]("Browser " + aqConvert["IntToStr"](i) + " : " + browser["Description"]);
  }
}

For more examples of using this property, see Launch Web Browsers, Parameterizing the Browser for a Test Run and Running Tests in Multiple Browsers topics.

See Also

Browsers Object
Run Method
Navigate Method
RemoteItem Property

Highlight search results