Objects.Items Method

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

Description

The Objects.Items method lets you obtain the StoredObject object that provides a scripting interface to an item of the Objects collection.

Declaration

Objects.Items(ObjectName)

ObjectName [in]    Required    String    
Result A StoredObject object

Applies To

The method is applied to the following object:

Parameters

The method has the following parameter:

ObjectName

The unique name of the desired item in the collection. Item names are shown in the Name column of the Objects editor.

Result Value

The StoredObject object that corresponds to the item with the given name.

Remarks

If the specified item does not exist, an error will occur. To check whether the specified item belongs to the collection, use the Contains method.

Example

The following code demonstrates how you can access the desired item of the Objects collection and the properties stored in this item.

JavaScript, JScript

function Test1()
{
  // Obtains the specified property collection
  StoredObject = Objects.Items("MyCollection");
  Log.Message("The total number of property values stored by the collection: " + StoredObject.PropertyCount);

  // Access the specified stored property
  StoredObjectProperty = StoredObject.Properties(0);
    // --or--
  // StoredObjectProperty = StoredObject.PropertyByName("Caption");
  PropertyName = StoredObjectProperty.Name;
  PropertyValue = StoredObjectProperty.Value;
  Log.Message(PropertyName + " = " + PropertyValue);
}

Python

def Test1():
  # Obtains the specified property collection 
  StoredObject = Objects.Items("MyCollection")
  Log.Message("The total number of property values stored by the collection: " + str(StoredObject.PropertyCount))
  # Access the specified stored property  
  StoredObjectProperty = StoredObject.Properties[0]
  # --or-- 
  # StoredObjectProperty = StoredObject.PropertyByName["Caption"]
  PropertyName = StoredObjectProperty.Name 
  PropertyValue = StoredObjectProperty.Value
  Log.Message(PropertyName + " = " + str(PropertyValue))

VBScript

Sub Test1
  ' Obtains the specified property collection
  Set StoredObject = Objects.Items("MyCollection")
  Log.Message("The total number of property values stored by the collection: " & StoredObject.PropertyCount)

  ' Access the specified stored property
  Set StoredObjectProperty = StoredObject.Properties(0)
    ' --or--
  ' Set StoredObjectProperty = StoredObject.PropertyByName("Caption")
  PropertyName = StoredObjectProperty.Name
  PropertyValue = StoredObjectProperty.Value
  Log.Message(PropertyName & " = " & PropertyValue)
End Sub

DelphiScript

procedure Test1;
begin
  // Obtains the specified property collection
  StoredObject := Objects.Items('MyCollection');
  Log.Message('The total number of property values stored by the collection: ' + StoredObject.PropertyCount);

  // Access the specified stored property
  StoredObjectProperty := StoredObject.Properties(0);
    // --or--
  // StoredObjectProperty := StoredObject.PropertyByName('Caption');
  PropertyName := StoredObjectProperty.Name;
  PropertyValue := StoredObjectProperty.Value;
  Log.Message(PropertyName + ' = ' + PropertyValue);
end;

C++Script, C#Script

function Test1()
{
  // Obtains the specified property collection
  StoredObject = Objects["Items"]("MyCollection");
  Log["Message"]("The total number of property values stored by the collection: " + StoredObject["PropertyCount"]);

  // Access the specified stored property
  StoredObjectProperty = StoredObject["Properties"](0);
    // --or--
  // StoredObjectProperty = StoredObject["PropertyByName"]("Caption");
  PropertyName = StoredObjectProperty["Name"];
  PropertyValue = StoredObjectProperty["Value"];
  Log["Message"](PropertyName + " = " + PropertyValue);
}

See Also

About Objects Collection
Compare Method
Save Method
StoredObject

Highlight search results