Position Property (MenuItem Objects)

Applies to TestComplete 15.68, last modified on October 03, 2024

Description

The Position property returns the menu item’s index (position) in the menu. Indexes can be useful when working with owner-drawn and bitmap menu items, as these items may hold no text.

Declaration

TestObj.Position

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 zero-based index of the menu item.

Remarks

The total number of items in the menu is specified by the Menu.Count property.

Menu separators also count as items.

Example

The following code snippet obtains the index of the Edit menu item in the Windows Notepad main menu and posts the index to the test log.

JavaScript, JScript

function MenuItemSample()
{
  // Obtains the Windows Notepad main menu
  var MainMenu = Sys.Process("Notepad").Window("Notepad", "*").MainMenu;
  // Obtains the Edit menu item
  var Item = MainMenu.Items("Edit");
  // Obtains the index of the Edit menu item
  // And posts it to the test log
  var Indx = Item.Position;
  Log.Message("The Edit menu item index is " + aqConvert.IntToStr(Indx));

}

Python

def MenuItemSample():
  # Obtains the Windows Notepad main menu
  MainMenu = Sys.Process("Notepad").Window("Notepad", "*").MainMenu
  # Obtains the Edit menu item
  Item = MainMenu.Items["Edit"]
  # Obtains the index of the Edit menu item
  # And posts it to the test log
  Indx = Item.Position
  Log.Message("The Edit menu item index is " + aqConvert.IntToStr(Indx))

VBScript

Sub MenuItemSample

  ' Obtains the Windows Notepad main menu
  Set MainMenu = Sys.Process("Notepad").Window("Notepad", "*").MainMenu
  ' Obtains the Edit menu item
  Set Item = MainMenu.Items("Edit")
  ' Obtains the index of the Edit menu item
  ' And posts it to the test log
  Indx = Item.Position
  Log.Message "The Edit menu item index is " & aqConvert.IntToStr(Indx)

End Sub

DelphiScript

procedure MenuItemSample();
var
  MainMenu, Item : OleVariant;
  Indx : integer;
begin
  // Obtains the Windows Notepad main menu
  MainMenu := Sys.Process('Notepad').Window('Notepad', '*').MainMenu;
  // Obtains the Edit menu item
  Item := MainMenu.Items('Edit');
  // Obtains the index of the Edit menu item
  // And posts it to the test log
  Indx := Item.Position;
  Log.Message('The Edit menu item index is ' + aqConvert.IntToStr(Indx));

end;

C++Script, C#Script

function MenuItemSample()
{
  // Obtains the Windows Notepad main menu
  var MainMenu = Sys["Process"]("Notepad")["Window"]("Notepad", "*")["MainMenu"];
  // Obtains the Edit menu item
  var Item = MainMenu["Items"]("Edit");
  // Obtains the index of the Edit menu item
  // And posts it to the test log
  var Indx = Item["Position"];
  Log["Message"]("The Edit menu item index is " + aqConvert["IntToStr"](Indx));

}

See Also

Addressing Menu Items in Desktop Windows Applications
Caption Property (MenuItem Objects)
Id Property (MenuItem Objects)
Count Property (Menu Controls)

Highlight search results