Checked Property (MenuItem Objects)

Applies to TestComplete 14.10, last modified on June 5, 2019

Description

The MenuItem.Checked property returns True, if the menu item is Checked. Otherwise - False. To check or uncheck menu items, use the Menu.Check method.

Declaration

TestObj.Checked

Read-Only Property Boolean
TestObj A variable, parameter or expression that specifies a reference to one of the objects listed in the Applies To section

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.

Property Value

True, if the menu item is Checked. Otherwise - False.

Example

The following code snippet obtains the Word Wrap item of the Format menu in Windows Notepad and checks the state of the menu item.

JavaScript, JScript

function MenuItemSample()
{
  var Notepad, Window, MainMenu, Submenu, Item;
  // Obtains the Windows Notepad main menu
  Notepad = Sys.Process("Notepad");
  Window = Notepad.Window("Notepad", "*");
  MainMenu = Window.MainMenu;
  // Obtains the Format submenu
  Submenu = MainMenu.Items("Format").SubMenu;

  // Obtains the "Word Wrap" menu item
  Item = Submenu.Items("Word Wrap");

  // Checks the state of the menu item
  if (Item.Checked)
    Log.Message("The Word Wrap item is checked");
  else
    Log.Message("The Word Wrap item is unchecked");

}

Python

def MenuItemSample():
  # Obtains the Windows Notepad main menu
  Notepad = Sys.Process("Notepad")
  Window = Notepad.Window("Notepad", "*")
  MainMenu = Window.MainMenu
  # Obtains the Format submenu
  Submenu = MainMenu.Items["Format"].SubMenu

  # Obtains the "Word Wrap" menu item
  Item = Submenu.Items["Word Wrap"]

  # Checks the state of the menu item
  if Item.Checked:
    Log.Message("The Word Wrap item is checked")
  else:
    Log.Message("The Word Wrap item is unchecked")

VBScript

Sub MenuItemSample

  ' Obtains the Windows Notepad main menu
  Set Notepad = Sys.Process("Notepad")
  Set Window = Notepad.Window("Notepad", "*")
  Set MainMenu = Window.MainMenu
  ' Obtains the Format submenu
  Set Submenu = MainMenu.Items("Format").SubMenu

  ' Obtains the "Word Wrap" menu item
  Set Item = Submenu.Items("Word Wrap")

  ' Checks the state of the menu item
  If Item.Checked Then
    Log.Message "The Word Wrap item is checked"
  Else
    Log.Message "The Word Wrap item is unchecked"
  End If

End Sub

DelphiScript

procedure MenuItemSample();
var Notepad, Window, MainMenu, Submenu, Item;
begin
  // Obtains the Windows Notepad main menu
  Notepad := Sys.Process('Notepad');
  Window := Notepad.Window('Notepad', '*');
  MainMenu := Window.MainMenu;
  // Obtains the Format submenu
  Submenu := MainMenu.Items('Format').SubMenu;

  // Obtains the "Word Wrap" menu item
  Item := Submenu.Items('Word Wrap');

  // Checks the state of the menu item
  if Item.Checked then
    Log.Message('The Word Wrap item is checked')
  else
    Log.Message('The Word Wrap item is unchecked');

end;

C++Script, C#Script

function MenuItemSample()
{
  var Notepad, Window, MainMenu, Submenu, Item;
  // Obtains the Windows Notepad main menu
  Notepad = Sys["Process"]("Notepad");
  Window = Notepad["Window"]("Notepad", "*");
  MainMenu = Window.MainMenu;
  // Obtains the Format submenu
  Submenu = MainMenu["Items"]("Format")["SubMenu"];

  // Obtains the "Word Wrap" menu item
  Item = Submenu["Items"]("Word Wrap");

  // Checks the state of the menu item
  if (Item["Checked"])
    Log["Message"]("The Word Wrap item is checked");
  else
    Log["Message"]("The Word Wrap item is unchecked");

}

See Also

Checking Menu Item's State
Enabled Property (MenuItem Objects)
IsRadioCheck Property (MenuItem Objects)

Highlight search results