Check Action (Menu Controls)

Applies to TestComplete 14.72, last modified on April 22, 2021

Description

Use Check for checking or unchecking the specified item of a menu or submenu.

Declaration

TestObj.Check(ItemChecked)

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    
Checked [in]    Required    Boolean    
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 parameters:

Item

Specifies the item you want to check or uncheck.

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.Check("View|Show Toolbar", true)

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.Check(0, true)

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.Check("Edit|[1]|[0]", true)

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.

Checked

Specifies whether the item will be checked (True) or unchecked (False).

Result Value

None.

Remarks

If the item is not found in the menu, Check fails and posts an error message to the test log. Note that the mouse pointer is not moved, as it would be using Click.

Check 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 check the Format | Word Wrap menu item using item captions:

JavaScript, JScript

function MenuSample()
{
  var Notepad = Sys.Process("Notepad");
  var wndNotepad = Notepad.Window("Notepad", "*");
  // Obtains the Notepad main menu
  var MainMenu = wndNotepad.MainMenu;
  // Checks the Format | Word Wrap item of the main menu
  MainMenu.Check("Format|Word Wrap", true);

}

Python

def MenuSample():
  Notepad = Sys.Process("Notepad")
  wndNotepad = Notepad.Window("Notepad", "*")
  # Obtains the Notepad main menu
  MainMenu = wndNotepad.MainMenu
  # Checks the Format | Word Wrap item of the main menu
  MainMenu.Check("Format|Word Wrap", True)

VBScript

Sub MenuSample

  Set Notepad = Sys.Process("Notepad")
  Set wndNotepad = Notepad.Window("Notepad", "*")
  ' Obtains the Notepad main menu
  Set MainMenu = wndNotepad.MainMenu
  ' Checks the Format | Word Wrap item of the main menu
  Call MainMenu.Check("Format|Word Wrap", True)

End Sub

DelphiScript

procedure MenuSample();
var Notepad, wndNotepad, MainMenu;
begin
  Notepad := Sys.Process('Notepad');
  wndNotepad := Notepad.Window('Notepad', '*');
  // Obtains the Notepad main menu
  MainMenu := wndNotepad.MainMenu;
  // Checks the Format | Word Wrap item of the main menu
  MainMenu.Check('Format|Word Wrap', true);

end;

C++Script, C#Script

function MenuSample()
{
  var Notepad = Sys["Process"]("Notepad");
  var wndNotepad = Notepad["Window"]("Notepad", "*");
  // Obtains the Notepad main menu
  var MainMenu = wndNotepad["MainMenu"];
  // Checks the Format | Word Wrap item of the main menu
  MainMenu["Check"]("Format|Word Wrap", true);

}

See Also

Selecting Menu Items
Count Property (Menu Controls)
Items Property (Menu Controls)
Click Action (Menu Controls)
Close Action (Menu Controls)
Select Action (Menu Controls)

Highlight search results