Click Action (Menu Controls)

Applies to TestComplete 15.69, last modified on November 13, 2024

Description

Click moves the mouse pointer to the specified menu or submenu item and then simulates a mouse click.

Declaration

TestObj.Click(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 click.

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.Click("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.Click(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.Click("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 specified item is not found in the menu, Click fails and posts an error message to the test log. To select the item without moving the mouse pointer, use the Select action.

Click 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 illustrates how to “click” the File | Open menu item using item indexes:

JavaScript, JScript

function Test()
{
  p = Sys.Process("NOTEPAD");
  w = p.Window("Notepad", "*");
  w.Activate();
  // analogue of w.MainMenu.Click("File|Open")
  w.MainMenu.Click("[0|1]");
}

Python

def Test():
  p = Sys.Process("NOTEPAD")
  w = p.Window("Notepad", "*")
  w.Activate()
  # analogue of w.MainMenu.Click("File|Open")
  w.MainMenu.Click("[0|1]")

VBScript

Sub Test
  Set p = Sys.Process("NOTEPAD")
  Set w = p.Window("Notepad", "*")
  w.Activate
  ' analogue of w.MainMenu.Click "File|Open"
  w.MainMenu.Click "[0|1]"
End Sub

DelphiScript

procedure Test();
var p, w: variant;
begin
  p := Sys.Process('NOTEPAD');
  w := p.Window('Notepad', '*');
  w.Activate;
  // analogue of w.MainMenu.Click('File|Open')
  w.MainMenu.Click('[0|1]');
end;

C++Script, C#Script

function Test()
{
  p = Sys["Process"]("NOTEPAD");
  w = p["Window"]("Notepad", "*");
  w["Activate"]();
  // analogue of w["MainMenu"]["Click"]("File|Open")
  w["MainMenu"]["Click"]("[0|1]");
}

See Also

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

Highlight search results