Select Action (Menu Controls)

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

Description

This method selects the specified menu or submenu item by placing the mouse pointer over it. Unlike Click, Select does not perform a click on the menu item.

Declaration

TestObj.Select(Item)

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    
Result None

Applies To

The method is applied to the following object:

View Mode

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

Parameters

The method has the following parameter:

Item

Specifies the item you want to hover over with the mouse cursor.

Submenu items should be specified by the “full path” starting from the top-level menu. To separate items in the “path”, use the vertical character (“ | ”). For instance:

w.MainMenu.Select("View|Show Toolbar")

An item can be specified by name or by index in the menu. If you specify the item by name, TestComplete can treat it as case-sensitive or case-insensitive according to the Use case-sensitive parameters project property. You can use wildcards (* and ?) in the item name, where the asterisk corresponds to a string of any length and the question mark - to any single character.

The item name should not include the special character that is used to create an access key for that item. To specify the access key, developers typically insert the ampersand symbol before the desired character in the item name. So, the 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” underscores. Typically, only the first found ampersand or underscore symbol is treated as a special character. All other ampersands and underscores are treated as ordinary characters.

You can use the index to specify the desired submenu item. For instance:

w.MainMenu.Select(0)

If you use the index in the path, put the index number in brackets. That is, the name is interpreted as an index if the first character is [ and the last is ]. In this case, the brackets must enclose nothing but the index number (no spaces, etc.)

w.MainMenu.Select("Edit|[1]|[0]")

Indexes begin from 0, and menu separators count as items. Indexes can be useful when working with menu items of the MFT_OWNERDRAW or MFT_BITMAP style, as these items may hold no text.

Result Value

None.

Remarks

If the item is not found in the menu, Select fails and posts an error message to the test log. Note that the specified menu item is only hovered over with the mouse pointer; the click on the item is not performed.

Select can be applied to top-level menus only. To work with submenu items, specify the full path to them in the Item parameter (see the parameter description).

Example

The following example demonstrates how to select items of the Windows Notepad main menu.

JavaScript, JScript

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

  // Selects the Format | Word Wrap menu item
  MainMenu.Select("Format|Word Wrap");

  // Selects the Help menu item
  MainMenu.Select("Help");

  // Selects the Edit menu item
  MainMenu.Select(1);

}

Python

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

  # Selects the Format | Word Wrap menu item
  MainMenu.Select("Format|Word Wrap")

  # Selects the Help menu item
  MainMenu.Select("Help")

  # Selects the Edit menu item
  MainMenu.Select(1)

VBScript

Sub MenuSample

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

  ' Selects the Format | Word Wrap menu item
  MainMenu.Select("Format|Word Wrap")

  ' Selects the Help menu item
  MainMenu.Select("Help")

  ' Selects the Edit menu item
  MainMenu.Select(1)

End Sub

DelphiScript

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

  // Selects the Format | Word Wrap menu item
  MainMenu.Select('Format|Word Wrap');

  // Selects the Help menu item
  MainMenu.Select('Help');

  // Selects the Edit menu item
  MainMenu.Select(1);

end;

C++Script, C#Script

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

  // Selects the Format | Word Wrap menu item
  MainMenu["Select"]("Format|Word Wrap");

  // Selects the Help menu item
  MainMenu["Select"]("Help");

  // Selects the Edit menu item
  MainMenu["Select"](1);

}

See Also

Selecting Menu Items in Desktop Windows Applications
Count Property (Menu Controls)
Items Property (Menu Controls)
Check Action (Menu Controls)
Click Action (Menu Controls)
Close Action (Menu Controls)

Highlight search results