BrowserWindow Method

Applies to TestComplete 15.68, last modified on October 16, 2024

Description

The Browser.BrowserWindow method lets you access an opened browser window as a BrowserWindow test object. You can use this object to manipulate the browser window, for example, maximize it or position it on the screen.

Note: The BrowserWindow method accesses a browser window, not a web page in that window. To access web pages opened in a browser, use the Browser.Page method.
To check if a browser window exists, use the Browser.WaitBrowserWindow method rather than Browser.BrowserWindow. This way you will avoid the “Unable to find the object” error in case the specified browser is not running. For more information, see Checking Whether an Object Exists.

Declaration

TestObj.BrowserWindow(ObjectIdentifier)

TestObj A variable, parameter or expression that specifies a reference to one of the objects listed in the Applies To section
ObjectIdentifier [in]    Required    Integer    
Result A BrowserWindow object

Applies To

The method is applied to the following object:

View Mode

To view this method in the Object Browser panel and in other panels and dialogs, activate the Advanced view mode.

Parameters

The method has the following parameter:

ObjectIdentifier

A zero-based index of the browser window among all windows opened in the browser. The first browser window has the index of 0, the second - 1, and so on.

Result Value

A BrowserWindow object corresponding to the specified browser window.

Remarks

If a browser window with the specified index was not found, the Browser method posts the “Unable to find the object” error to the test log. To avoid the error in case the browser window was not found, use the WaitBrowserWindow method to check if that window currently exists. For more information, see Checking Whether an Object Exists and Waiting for an Object, Process or Window Activation.

If you use Name Mapping, you typically refer to browser windows as Aliases.browser.BrowserWindow, Aliases.browser.BrowserWindow1 and so on, rather than using the Browser.BrowserWindow(ObjectIdentifier) method.

Example

The following example reads the title of a browser window.

JavaScript, JScript

function Test()
{
  Browsers.Item("iexplore").Run("http://smartbear.com");
  var title = Sys.Browser().BrowserWindow(0).WndCaption;
  Log.Message(title);
}

Python

def Test():
  Browsers.Item["iexplore"].Run("http://smartbear.com")
  title = Sys.Browser().BrowserWindow(0).WndCaption
  Log.Message(title)

VBScript

Sub Test
  Dim title

  Call Browsers.Item("iexplore").Run("http://smartbear.com")
  title = Sys.Browser().BrowserWindow(0).WndCaption
  Call Log.Message(title)
End Sub

DelphiScript

procedure Test;
var title;
begin
  Browsers.Item('iexplore').Run('http://smartbear.com');
  title := Sys.Browser().BrowserWindow(0).WndCaption;
  Log.Message(title);
end;

C++Script, C#Script

function Test()
{
  Browsers["Item"]("iexplore")["Run"]("http://smartbear.com");
  var title = Sys["Browser"]()["BrowserWindow"](0)["WndCaption"];
  Log["Message"](title);
}

See Also

BrowserWindow Object
WaitBrowserWindow Method
Classic Web Testing
Understanding Web Object Identification and Object Models

Highlight search results