Count Property (Menu Controls)

Applies to TestComplete 15.70, last modified on December 17, 2024

Description

The Menu.Count property returns the number of items in the specified Menu control. This number includes menu separators. To get access to individual items, use the Items property.

Declaration

TestObj.Count

Read-Only Property Integer
TestObj A variable, parameter or expression that specifies a reference to one of the objects listed in the Applies To section

Applies To

The property is applied to the following object:

View Mode

To view this property in the Object Browser panel and in other panels and dialogs, activate the Advanced view mode.

Property Value

A total number of items in the menu.

Example

The following example demonstrates how to use the Count property to define the total number of items in a menu and iterate through them.

JavaScript, JScript

function MenuSample()
{
  // Obtains the Notepad main menu
  var MainMenu = Sys.Process("Notepad").Window("Notepad", "*").MainMenu;

  // Defines the total number of main menu items
  var Count = MainMenu.Count;
  // Iterates through the menu items
  for (var i = 0; i < Count; i++)
  {
    // Obtains the menu item
    var Item = MainMenu.Items(i);
    // Posts the item caption to the test log
    Log.Message(Item.Caption);
  }

}

Python

def MenuSample():
  # Obtains the Notepad main menu
  MainMenu = Sys.Process("Notepad").Window("Notepad", "*").MainMenu

  # Defines the total number of main menu items
  Count = MainMenu.Count
  # Iterates through the menu items
  for i in range ( 0,  Count ):
    # Obtains the menu item
    Item = MainMenu.Items[i]
    # Posts the item caption to the test log
    Log.Message(Item.Caption)

VBScript

Sub MenuSample

  ' Obtains the Notepad main menu
  Set MainMenu = Sys.Process("Notepad").Window("Notepad", "*").MainMenu

  ' Defines the total number of main menu items
  Count = MainMenu.Count
  ' Iterates through the menu items
  For i = 0 To Count - 1
    ' Obtains the menu item
    Set Item = MainMenu.Items(i)
    ' Posts the item caption to the test log
    Log.Message Item.Caption
  Next

End Sub

DelphiScript

procedure MenuSample();
var
  MainMenu, Item : OleVariant;
  Count, i : integer;
begin
  // Obtains the Notepad main menu
  MainMenu := Sys.Process('Notepad').Window('Notepad', '*').MainMenu;

  // Defines the total number of main menu items
  Count := MainMenu.Count;
  // Iterates through the menu items
  for i := 0 to Count - 1 do
  begin
    // Obtains the menu item
    Item := MainMenu.Items[i];
    // Posts the item caption to the test log
    Log.Message(Item.Caption);
  end;

end;

C++Script, C#Script

function MenuSample()
{
  // Obtains the Notepad main menu
  var MainMenu = Sys["Process"]("Notepad")["Window"]("Notepad", "*")["MainMenu"];

  // Defines the total number of main menu items
  var Count = MainMenu["Count"];
  // Iterates through the menu items
  for (var i = 0; i < Count; i++)
  {
    // Obtains the menu item
    var Item = MainMenu["Items"](i);
    // Posts the item caption to the test log
    Log["Message"](Item["Caption"]);
  }

}

See Also

Items Property (Menu Controls)
Check Action (Menu Controls)
Click Action (Menu Controls)
Close Action (Menu Controls)
Select Action (Menu Controls)

Highlight search results