ChildByName Property

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

Description

Use the ChildByName property to obtain a scripting interface to a child property collection of the collection to which StoredObjectObj provides access to.

Declaration

StoredObjectObj.ChildByName(Name)

Read-Only Property A StoredObject object
StoredObjectObj An expression, variable or parameter that specifies a reference to a StoredObject object
Name [in]    Required    String    

Applies To

The property is applied to the following object:

Parameters

The property has the following parameter:

Name

Specifies the name of the desired child collection.

Property Value

A StoredObject object that provides a scripting interface to a child property collection.

Remarks

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

If the specified child collection does not exist, ChildByName returns an empty value (Nothing in VBScript, None in Python, null in JavaScript, JScript, C++Script and C#Script, and nil in DelphiScript).

Example

The following code demonstrates how you can access the desired property collection and its child collections.

JavaScript, JScript

function Test1()
{
  // Obtains the specified property collection and returns the total number of its child collections
  StoredObject = Objects.Items("MyCollection");
  Log.Message(StoredObject.ChildCount);

  // Obtains a child property collection by its index and returns the collection's name
  ChildCollection = StoredObject.Children(0);
  Log.Message(ChildCollection.Name);

  // Obtains the child property collection by its name
  // ChildCollection = StoredObject.ChildByName("ChildCollectionName");
}

Python

def Test1():
  # Obtains the specified property collection and returns the total number of its child collections 
  StoredObject = Objects.Items("MyCollection")
  Log.Message(StoredObject.ChildCount)
  # Obtains a child property collection by its index and returns the collection's name 
  ChildCollection = StoredObject.Children[0]
  Log.Message(ChildCollection.Name)
  # Obtains the child property collection by its name 
  # ChildCollection = StoredObject.ChildByName("ChildCollectionName")

VBScript

Sub Test1
  ' Obtains the specified property collection and returns the total number of its child collections
  Set StoredObject = Objects.Items("MyCollection")
  Log.Message(StoredObject.ChildCount)

  ' Obtains a child property collection by its index and returns the collection's name
  Set ChildCollection = StoredObject.Children(0)
  Log.Message(ChildCollection.Name)

  ' Obtains the child property collection by its name
  ' Set ChildCollection = StoredObject.ChildByName("ChildCollectionName")
End Sub

DelphiScript

procedure Test1;
begin
  // Obtains the specified property collection and returns the total number of its child collections
  StoredObject := Objects.Items('MyCollection');
  Log.Message(StoredObject.ChildCount);

  // Obtains a child property collection by its index and returns the collection's name
  ChildCollection := StoredObject.Children(0);
  Log.Message(ChildCollection.Name);

  // Obtains the child property collection by its name
  // ChildCollection := StoredObject.ChildByName('ChildCollectionName');
end;

C++Script, C#Script

function Test1()
{
  // Obtains the specified property collection and returns the total number of its child collections
  StoredObject = Objects["Items"]("MyCollection");
  Log["Message"](StoredObject["ChildCount"]);

  // Obtains a child property collection by its index and returns the collection's name
  ChildCollection = StoredObject["Children"](0);
  Log["Message"](ChildCollection["Name"]);

  // Obtains the child property collection by its name
  // ChildCollection = StoredObject["ChildByName"]("ChildCollectionName");
}

See Also

Children Property
ChildCount Property

Highlight search results