Determining List Box Item Bounds in Desktop Windows Applications

Applies to TestComplete 15.47, last modified on January 20, 2023

Note: To learn how to simulate user actions over list box controls in web applications, see Working With List Box Controls in Web Applications.

While testing list box controls, you can use specific properties and methods of the corresponding program object to perform certain actions and obtain data stored in controls. You can call these methods and properties from your keyword tests, as well as from scripts. This topic describes how to work with the needed properties and methods from your scripts. However, when testing a control from your keyword test, you can use the same methods and properties calling them from keyword test operations. For more information, see Keyword Tests Basic Operations.

You may need to get information not only about a list box's height, width and coordinates, but also about dimensions of certain items. Since list box controls are associated with the Win32ListBox object, you can use its specific properties to work with certain items.

The wItemBounds property allows you to determine the bounds of the specified list box item. This property returns the Bounds object, which contains the parent-relative coordinates of lower-right and upper-left corners, the height and the width of a bounding rectangle. The following example posts the height and the width of the specified list box item to the log:

JavaScript, JScript

function Main()
{
  var p, w, ListBox, ItemBounds;

  // Obtain list box object
  p = Sys.Process("wordpad");
  Sys.Keys("~i[Enter]");
  w = p.Window("#32770", "Date and Time");
  ListBox = w.Window("ListBox", "", 1);

  // Obtain item bounds and post information to the log
  ItemBounds = ListBox.wItemBounds(2);
  Log.Message("Height: " + ItemBounds.Height);
  Log.Message("Width: " + ItemBounds.Width);
}

Python

def Main():

  # Obtain list box object 
  p = Sys.Process("wordpad")
  Sys.Keys("~i[Enter]")
  w = p.Window("#32770", "Date and Time")
  ListBox = w.Window("ListBox", "", 1)

  # Obtain item bounds and post information to the log 
  ItemBounds = ListBox.wItemBounds[2]
  Log.Message("Height: " + ItemBounds.Height)
  Log.Message("Width: " + ItemBounds.Width)

VBScript

Sub Main
  Dim p, w, ListBox, ItemBounds

  ' Obtain list box object
  Set p = Sys.Process("wordpad")
  Sys.Keys "~i[Enter]"
  Set w = p.Window("#32770", "Date and Time")
  Set ListBox = w.Window("ListBox", "", 1)

  ' Obtain item bounds and post information to the log
  Set ItemBounds = ListBox.wItemBounds(2)
  Log.Message("Height: " & ItemBounds.Height)
  Log.Message("Width: " & ItemBounds.Width)
End Sub

DelphiScript

procedure Main();
var p, w, ListBox, ItemBounds;
begin
  // Obtain list box object
  p := Sys.Process('wordpad');
  Sys.Keys('~i[Enter]');
  w := p.Window('#32770', 'Date and Time', 1);
  ListBox := w.Window('ListBox', '', 1);

  // Obtain item bounds and post information to the log
  ItemBounds := ListBox.wItemBounds[2];
  Log.Message('Height: ' + aqConvert.VarToStr(ItemBounds.Height));
  Log.Message('Width: ' + aqConvert.VarToStr(ItemBounds.Width));
end;

C++Script, C#Script

function Main()
{
  var p, w, ListBox, ItemBounds;

  // Obtain list box object
  p = Sys["Process"]("wordpad");
  Sys.Keys("~i[Enter]");
  w = p["Window"]("#32770", "Date and Time", 1);
  ListBox = w["Window"]("ListBox", "", 1);

  // Obtain item bounds and post information to the log
  ItemBounds = ListBox["wItemBounds"](2);
  Log["Message"]("Height: " + ItemBounds.Height);
  Log["Message"]("Width: " + ItemBounds.Width);
}

See Also

Working With List Box Controls in Desktop Windows Applications
wItemBounds Property (ListBox Controls)
Bounds Object
Working With List Box Controls in Web Applications

Highlight search results