ItemCollection Object

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

Description

The ItemCollection object is a helper object used to work with the following controls:

The ItemCollection object provides access to a collection of items of the tested control. To get the object, use the tested control’s wItems property.

To access an individual item of the collection, use the Item property of the ItemCollection object.

If the returned item has subitems, use the Items property to get them.

Using these properties, you can iterate through the hierarchy of a control's items and get access to any needed item.

Members

Example

The example below demonstrates how to get items and subitems of a ribbon control and simulate user actions on them:

JavaScript, JScript

function TestRibbonControlItems()
{
  // Get the ribbon control
  var myRibbon = Sys.Process("MyRibbonApp").WinFormsObject("frmMain").WinFormsObject("ribbonControl");
  // Get the collection of ribbon control's items
  var ribbonItems = myRibbon.wItems;
  // Get the "Home" item of the ribbon control
  var home = ribbonItems.Item("Home");

  // Get the collection of the "Home" item’s subitems
  // And then get the "Paste" subitem
  var paste = home.Items.Item("Paste");
  // Simulate a click on the "Paste" subitem
  paste.Click();

  // Get the "Bold" subitem
  var bold = home.Items.Item("Bold");
  // Check the state of the “Bold” subitem
  if (bold.State == 0)
    Log.Message("Item 'Bold' is disabled")
  else
    Log.Message("Item 'Bold' is enabled")
  // Set the item's state to 'enabled'
  bold.Check(1);


}

Python

def TestRibbonControlItems():
   # Get the ribbon control
   myRibbon = Sys.Process("MyRibbonApp").WinFormsObject("frmMain").WinFormsObject("ribbonControl")
   # Get the collection of ribbon control’s items
   ribbonItems = myRibbon.wItems
   # Get the "Home" item of the ribbon control
   home = ribbonItems.Item["Home"]

   # Get the collection of the "Home" item's subitems
   # And then get the "Paste" subitem
   paste = home.Items.Item["Paste"]
   # Simulate a click on the "Paste" subitem
   paste.Click()

   # Get the "Bold" subitem
   bold = home.Items.Item["Bold"]
   # Check the state of the "Bold" subitem
   if (bold.State == 0):
     Log.Message("Item 'Bold' is disabled")
   else:
     Log.Message("Item 'Bold' is enabled")
   # Set the item's state to 'enabled'
   bold.Check(1)

VBScript

Sub TestRibbonControlItems()
  ' Get the ribbon control
  Set myRibbon = Sys.Process("MyRibbonApp").WinFormsObject("frmMain").WinFormsObject("ribbonControl")
  ' Get the collection of ribbon control’s items
  Set ribbonItems = myRibbon.wItems
  ' Get the "Home" item of the ribbon control
  Set home = ribbonItems.Item("Home")

  ' Get the collection of the "Home" item’s subitems
  ' And then get the "Paste" subitem
  Set paste = home.Items.Item("Paste")
  ' Simulate a click on the "Paste" subitem
  paste.Click

  ' Get the "Bold" subitem
  Set bold = home.Items.Item("Bold")
  ' Check the state of the "Bold" subitem
  If bold.State = 0 Then
    Log.Message("Item 'Bold' is disabled")
  Else
    Log.Message("Item 'Bold' is enabled")
  End If
    ' Set the item's state to 'enabled'
  bold.Check(1)

  …
End Sub

DelphiScript

procedure TestRibbonControlItems();
var myRibbon, ribbonItems, home, paste,bold;
begin
  // Get the ribbon control
  myRibbon := Sys.Process('MyRibbonApp').WinFormsObject('frmMain').WinFormsObject('ribbonControl');
  // Get the collection of ribbon control’s items
  ribbonItems := myRibbon.wItems;
  // Get the "Home" item of the ribbon control
  home := ribbonItems.Item('Home');

  // Get the collection of the "Home" item's subitems
  // And then get the "Paste" subitem
  paste := home.Items.Item('Paste');
  // Simulate a click on the "Paste" subitem
  paste.Click;

  // Get the "Bold" subitem
  bold := home.Items.Item('Bold');
  // Check the state of the "Bold" subitem
  if bold.State = 0 then
    Log.Message('Item ''Bold'' is disabled')
  else
    Log.Message('Item ''Bold'' is enabled');
  // Set the item's state to "enabled"
  bold.Check(1);

  …
end;

C#Script

function TestRibbonControlItems()
{
  // Get the ribbon control
  var myRibbon = Sys["Process"]("MyRibbonApp")["WinFormsObject"]("frmMain")["WinFormsObject"]("ribbonControl");
  // Get the collection of ribbon control's items
  var ribbonItems = myRibbon["wItems"];
  // Get the "Home" item of the ribbon control
  var home = ribbonItems["Item"]("Home");

  // Get the collection of the "Home" item’s subitems
  // And then get the "Paste" subitem
  var paste = home["Items"]["Item"]("Paste");
  // Simulate a click on the "Paste" subitem
  paste["Click"]();

  // Get the "Bold" subitem
  var bold = home["Items"]["Item"]("Bold");
  // Check the state of the "Bold" subitem
  if (bold["State"] == 0)
    Log["Message"]("Item 'Bold' is disabled")
  else
    Log["Message"]("Item 'Bold' is enabled")
  // Set the item's state to 'enabled'
  bold["Check"](1);


}

See Also

Item Property (ItemCollection Objects)

Highlight search results