Description
The Menu.Items
property returns a MenuItem
object that provides access to the menu item specified by its index. The total number of items in the menu is specified by the Count
property.
Declaration
TestObj.Items(Item)
Read-Only Property | A MenuItem object |
TestObj | A variable, parameter or expression that specifies a reference to one of the objects listed in the Applies To section | |||
Item | [in] | Required | Variant |
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.
Parameters
The property has the following parameter:
Item
Specifies the item you want to get. An item can be specified by its name or index in the menu:
Log.Message ( w.MainMenu.Items("File").Caption )
Log.Message ( w.MainMenu.Items(0).Caption )
The index is zero-based, that is, the first item has an index of 0, the second - 1, and so on. The index of the last item is Count
- 1.
If you specify an item by its name, TestComplete will treat this name as case-sensitive or case-insensitive according to the Use case-sensitive parameters project property. You can use wildcards (* and ?) in item names, where the asterisk corresponds to a string of any length and the question mark - to any single character.
An item name should not include a special character that is used to create an access key for that item. To specify an access key, developers typically insert an ampersand before the desired character in the item name. So, an ampersand is one of these special characters. Another special character is an underscore. It is used to specify access keys for WPF menu items. So, if you are working with WPF menus, you should specify item names that do not include these “special” characters. Typically, only the first found ampersand or underscore is treated as a special character. The other ampersands and underscores are treated as ordinary characters.
Property Value
A MenuItem
object that provides scripting interface to the desired menu item.
Remarks
If you use Python or DelphiScript, you should enclose the parameter of the Items
property in square brackets: Items[Item]
.
Separators are also treated as menu items.
Example
The following example demonstrates how to obtain a menu item by its caption.
JavaScript, JScript
{
// Obtains the Notepad main menu
var MainMenu = Sys.Process("Notepad").Window("Notepad", "*").MainMenu;
// Obtains a menu item by its caption
var Item = MainMenu.Items("File")
}
Python
def MenuSample():
# Obtains the Notepad main menu
MainMenu = Sys.Process("Notepad").Window("Notepad", "*").MainMenu
# Obtains a menu item by its caption
Item = MainMenu.Items["File"]
VBScript
' Obtains the Notepad main menu
Set MainMenu = Sys.Process("Notepad").Window("Notepad", "*").MainMenu
' Obtains a menu item by its caption
Set Item = MainMenu.Items("File")
End Sub
DelphiScript
var Mainmenu, Item;
begin
// Obtains the Notepad main menu
MainMenu := Sys.Process('Notepad').Window('Notepad', '*').MainMenu;
// Obtains a menu item by its caption
Item := MainMenu.Items('File')
end;
C++Script, C#Script
{
// Obtains the Notepad main menu
var MainMenu = Sys["Process"]("Notepad")["Window"]("Notepad", "*")["MainMenu"];
// Obtains a menu item by its caption
var Item = MainMenu["Items"]("File")
}
See Also
Addressing Menu Items in Desktop Windows Applications
Count Property (Menu Controls)
Check Action (Menu Controls)
Click Action (Menu Controls)
Close Action (Menu Controls)
Select Action (Menu Controls)