Child Property

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

Description

The TestComplete log consists of log items organized into a tree-like structure. Use the Child property to obtain the child item of the current log item. The total number of child items is specified by the ChildCount property.

Declaration

LogItemObj.Child(Index)

Read-Only Property A LogItem object
LogItemObj An expression, variable or parameter that specifies a reference to a LogItem object
Index [in]    Required    Integer    

Applies To

The property is applied to the following object:

Parameters

The property has the following parameter:

Index

The index of the desired child log item. The index is zero-based, that is, the first child item has the index 0, the second - 1, and so on. Index of the last child item is ChildCount - 1.

Property Value

A LogItem object representing the desired child log item.

Remarks

If you use Python or DelphiScript, you should enclose the parameter of the Child property in square brackets: Child[Index].

Example

The code below obtains the names of all child elements that belong to the current log item and then posts these names to the test log.

JavaScript, JScript

function ChildrenNames()
{
  // Obtains a collection of logs
  var LogsCol = Project.Logs;
  // Obtains the first log item
  var LogItem = LogsCol.LogItem(0);
  
  // Obtains the number of child elements
  // that belong to the log item
  var Num = LogItem.ChildCount;
  // Iterates through the child items
  for (var i = 0; i < Num; i++)
  {
    // Obtains the name of the current log item
    var Name = LogItem.Child(i).Name;
    Log.Message(Name);
  }
}

Python

def ChildrenNames():
  # Obtains a collection of logs
  LogsCol = Project.Logs
  # Obtains the first log item
  LogItem = LogsCol.LogItem[0]
  # Obtains the number of child elements
  # that belong to the log item
  Num = LogItem.ChildCount
  # Iterates through the child items
  for i in range(0, Num):
    # Obtains the name of the current log item
    Name = LogItem.Child[i].Name
    Log.Message(Name)

VBScript

Sub ChildrenNames()

  ' Obtains a collection of logs
  Set LogsCol = Project.Logs
  ' Obtains the first log item
  Set LogItem = LogsCol.LogItem(0)
  
  ' Obtains the number of child elements
  ' that belong to the log item
  Num = LogItem.ChildCount
  ' Iterates through the child items
  For i = 0 to (Num - 1)
    ' Obtains the name of the current log item
    Name = LogItem.Child(i).Name
    Log.Message(Name)
  Next
     
End Sub

DelphiScript

function ChildrenNames;
var LogsCol, LogItem, Num, i, Name;
begin

  // Obtains a collection of logs
  LogsCol := Project.Logs;
  // Obtains the first log item
  LogItem := LogsCol.LogItem[0];
  
  // Obtains the number of child elements
  // that belong to the log item
  Num := LogItem.ChildCount;
  // Iterates through the child items
  for i := 0 to (Num - 1) do
  begin
    // Obtains the name of the current log item
    Name := LogItem.Child[i].Name;
    Log.Message(Name);
  end;

end;

C++Script, C#Script

function ChildrenNames()
{
  // Obtains a collection of logs
  var LogsCol = Project["Logs"];
  // Obtains the first log item
  var LogItem = LogsCol["LogItem"](0);
  
  // Obtains the number of child elements
  // that belong to the log item
  var Num = LogItem["ChildCount"];
  // Iterates through the child items
  for (var i = 0; i < Num; i++)
  {
    // Obtains the name of the current log item
    var Name = LogItem["Child"](i)["Name"];
    Log["Message"](Name);
  }
}

See Also

Access Test Log Contents from Tests
LogItem Object
ChildCount Property
Data Property
DataCount Property

Highlight search results