ChildCount Property

Applies to TestComplete 14.40, last modified on April 22, 2021

Description

Objects can have one or more children. For instance, processes are children of the Sys object, windows are children of processes, and so on. The ChildCount property of an object returns the number of its direct children. Use this property to iterate through the list of child objects.

Declaration

TestObj.ChildCount

Read-Only Property Integer
TestObj A variable, parameter or expression that specifies a reference to one of the objects listed in the Applies To section

Applies To

All processes, windows, controls and onscreen objects.

View Mode

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

Property Value

The number of child objects of the current object.

Remarks

The child objects list can change dynamically. In this case, you can use the Refresh method of the tested object to update the actual list of its child objects.

Example

The following example demonstrates how to iterate through all child objects of an object. It iterates through the current active window’s children in a loop and posts their names to the test log.

JavaScript, JScript

function GetWindowNames()
{
  var w, i, wndChild;
  w = Sys.Desktop.ActiveWindow();
  Log.Message(w.Name, w.FullName);
  // Add a for loop that iterates through child objects
  for (i=0; i < w.ChildCount; i++)
  {
    wndChild = w.Child(i);
    // Post the current child name to the test log
    Log.Message(wndChild.Name, "", 0);
  }
}

Python

def GetWindowNames():
  w = Sys.Desktop.ActiveWindow()
  Log.Message(w.Name, w.FullName)
  # Add a for loop that iterates through child objects
  for i in range ( 0 , w.ChildCount):
    wndChild = w.Child(i)
    # Post the current child name to the test log
    Log.Message(wndChild.Name, "", 0)

VBScript

Sub GetWindowNames
  Set w = Sys.Desktop.ActiveWindow
  ' Add a for loop that iterates through child objects
  For i = 0 To w.ChildCount - 1
    Set wndChild = w.Child(i)
    ' Post the current child name to the test log
    Log.Message wndChild.Name
  Next
End Sub

DelphiScript

procedure GetWindowNames;
var
  i : integer;
  w, wndChild : OleVariant;
begin
  w := Sys.Desktop.ActiveWindow;
  Log.Message(w.Name, w.FullName);
  // Add a for loop that iterates through child objects
  for i := 0 to (w.ChildCount - 1) do
  begin
    wndChild := w.Child(i);
    // Post the current child name to the test log
    Log.Message(wndChild.Name, '', 0);
  end;
end;

C++Script, C#Script

function GetWindowNames()
{
  var w, i, wndChild;
  w = Sys["Desktop"]["ActiveWindow"]();
  Log["Message"](w["Name"], w["FullName"]);
  // Add a for loop that iterates through child objects
  for (i=0; i < w["ChildCount"]; i++)
  {
    wndChild = w["Child"](i);
    // Post the current child name to the test log
    Log["Message"](wndChild["Name"], "", 0);
  }
}

See Also

Child Method
Refresh Method

Highlight search results