Item Object

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

Description

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

It provides access to the control’s standard items to which specific actions are not applicable (for example, labels or separators).

To get the Item object, first get the collection of the tested control’s items by using the control's wItems property, and then use the collection’s Item property to get the needed item.

If the item that corresponds to the Item object has child items, in turn, you can get access to them via the Items property.

Members

Example

The example below shows how to get items and subitems of a ribbon control:

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

ItemCollection Object

Highlight search results