Applies to TestComplete 14.70, last modified on October 20, 2020

This topic provides a brief overview of simulating user actions over menus. It contains the following sections:

Basic Concepts

An object may have several types of menus associated with it: top-level windows may have the main menu, the system menu and the context menu, child windows and controls may also have a context menu. In TestComplete, menus are associated with the Menu object. This object provides a number of methods and properties that let you perform various menu operations:

Method or Property Description
Click Simulates a click on a menu item.
Check Simulates checking or unchecking of a menu item.
Select Simulates placing the mouse pointer over a menu item.
Items Provides access to individual menu items.
Count Returns the number of items in a menu.

Menus are not displayed in the application’s object tree in the Object Browser. Access to menus are provided via special properties of windows and controls:

While windows’ main and system menus are always accessible to the test engine, context menus must be displayed on screen first since TestComplete cannot invoke context menus automatically. To invoke a context menu, add a test operation that right-clicks the appropriate window or control or sends the Application key press to it.

The easiest way to add menu actions to your test is to record them. However, you can also add the appropriate test operations at design time. The remainder of this topic explains how you can do this. For more information about working with menus in tested applications, see Working With Menus.

Simulating Menu Actions in Keyword Tests

In keyword tests, you can simulate various menu operations using the Menu Action operation. Below are step-by-step instructions on adding and configuring this operation:

  • Open your keyword test in the Keyword Test editor.

  • If you are going to simulate a context menu action, you first need to add and configure the On-Screen Action operation that invokes that menu, otherwise the menu will not be available:

    • Add the On-Screen Action operation to your test. TestComplete will display the Operation Properties wizard.

    • Drag and drop the target glyph () to the window or control whose context menu you want to work with and press Next.

    • In the list of available methods, select ClickR and press Next.

    • Specify the coordinates of the point within the window or control where TestComplete should right-click and press Finish.

  • Add the Menu Action operation to the test. TestComplete will display the Operation Parameters wizard.

  • Choose the type of the menu you are going to work with: main, system or context and click Next.

  • Drag and drop the target glyph () to the window or control whose menu you want to work with and click Next. Note, that to pick a window you need to drop the target glyph to the window’s caption rather than the client area, because the latter may contain child controls.

  • In the list of available menu actions, choose the one you need and click Next.

  • Finally, specify the parameter values for the selected method. Most menu actions have a parameter that holds the “path” to the menu item, for example, File|New. See Addressing Menu Items.

  • Click Finish to save changes and to close the wizard. TestComplete will append the configured Menu Action operation to your test.

You can also simulate menu actions using the Call Object Method operation. For more information on how to perform daily tasks in keyword tests, see Common Tasks for Keyword Test Operations.

Simulating Menu Actions in Scripts

To simulate menu actions from a script routine, obtain the Menu object corresponding to the target menu and call the appropriate method of this object. For example, the following code snippet selects the File | New command in Notepad’s main menu (providing that Notepad is running):

JavaScript, JScript

var p, w;

p = Sys.Process("notepad");
w = p.Window("Notepad", "*");


p = Sys.Process("notepad")
w = p.Window("Notepad", "*")


Dim p, w

Set p = Sys.Process("notepad")
Set w = p.Window("Notepad", "*")
w.MainMenu.Click "File|New"


var p, w;
  p := Sys.Process('notepad');
  w := p.Window('Notepad', '*');

C++Script, C#Script

var p, w;

p = Sys["Process"]("notepad");
w = p["Window"]("Notepad", "*");

For more script samples and detailed information about performing various operations with menus, see the Working With Menus topic.

Using Low-Level and Native Menu Actions

If the application you are testing uses a third-party menu component that is not recognized by TestComplete, you can still work with this menu as a “black-box” onscreen object. For example, you can select items using the Click action or by simulating the items’ access keys. See Simulating Mouse Actions and Simulating Keystrokes.

If the tested application is an Open one, you can also use “native” methods and properties of the menu component to perform the desired actions. To find the method or property that can be used to perform the desired menu action, explore the menu component in the Object Browser, refer to the component’s documentation or ask the tested application’s developers. See Working With Third-Party Menus for more information.

See Also

Simulating User Actions
Working With Menus
Addressing Menu Items
Working With Third-Party Menus

Highlight search results