Working With Third-Party Menus in Desktop Windows Applications

Applies to TestComplete 15.63, last modified on April 23, 2024

TestComplete can work not only with standard Win32 menu controls, but also with menus in Java, JavaFX, .NET, Qt and WPF applications as well as menus created using popular menu components by Microsoft, Borland and other vendors. In applications that use standard Win32 menus, you would access main and context menus using the MainMenu and PopupMenu properties. In applications that use third-party menus, you should use special properties, which are listed in the tables below:

Properties That Provide Access to Main Menus
Component Name Property Required Plugin
Borland Action Menu Bar Window.ActionMainMenu VCL Control Support
ComponentOne Menus and Toolbars Window.C1MainMenu Component One Control Support
Developer Express XtraBars Window.XtraMainMenu Developer Express Control Support
Google Web Toolkit MenuBar GWTMenuBar.GWTMenu Google Web Toolkit Control Support
Infragistics UltraWinToolbars Window.UltraMainMenu Infragistics Control Support
Janus UI Controls Window.UICtrlsMainMenu Janus Systems Control Support
Java Application Main Menu Window.JMainMenu
JMenuBar.SwingMenu
Java Control Support
JavaFX Application Main Menu JFXMenuBar.JavaFXMenu JavaFX Control Support
Microsoft MenuStrip Class Library Window.StripMainMenu Microsoft Control Support
Qt Application Menu QtMenu.QtMenu
QtMenuBar.QtMenu
Qt Control Support
Syncfusion Essential Tools Menus Window.EssMainMenu Syncfusion Systems Control Support
WPF Application Main Menu WPFMenu.WPFMenu WPF Control Support
Properties that Provide Access to Context Menus
Component Name Property Required Plugin
Developer Express XtraBars XtraPopupMenu Developer Express Control Support
Infragistics UltraWinToolbars UltraPopupMenu Infragistics Control Support
Java Application Context Menu SwingPopupMenu Java Control Support
JavaFX Application Context Menu JavaFXPopupMenu JavaFX Control Support
Microsoft MenuStrip Class Library StripPopupMenu Microsoft Control Support
Qt Application Context Menu QtPopupMenu Qt Control Support

All of the listed properties, except for XtraPopupMenu, return a Menu object that provides access to the corresponding menu component. You can work with the listed third-party menus the same you work with standard Win32 menus, that is, you can select menu items using the Menu.Click method, access individual items using the Menu.Items, check the items' state using the MenuItem object properties, and so on.

As for the XtraPopupMenu property, it provides a scripting interface to the XtraPopupMenu object. Use this object to operate with context menus created with the Developer Express XtraBars Suite.

Despite the fact that the Menu and XtraPopupMenu objects provide different sets of specific properties and methods, the principles of working with them are similar since they provide access to certain menu items, and have a number of specific actions to work with these items.

However, if your application uses other third-party menu components, you will not be able to work with it via the Menu object. You can work with custom controls in black-box mode only, that is, you can simulate mouse clicks, record and play back low-level procedures, and so on. Below are some more effective approaches for working with custom menus:

  • You can select menu items using their access keys and shortcuts. To simulate keypresses, use the Keys action applied to the desired window or control or the Sys.Keys method. For more information on this approach, see Selecting Menu Items in Desktop Windows Applications.

  • If your application is Open, you can work with menus using internal properties and methods of the application’s objects. By exploring the menu in the Object Browser, you can find methods or properties that can be used to select menu items or check their state. You can also ask the tested application’s developers to learn which properties and methods can be used for this purpose.

  • If your custom menu control supports Microsoft Active Accessibility (MSAA), you use the Microsoft Active Accessibility Support plugin to access menu items. To enable the MSAA engine expose information about the menu control, you should specify the menu’s window class name (the WndClass property) in the project’s MSAA Options. For example, if you enable the “*” item, the MSAA engine will expose methods and properties of any existing window. For more information about testing applications that support Active Accessibility, see Using Microsoft Active Accessibility.

The example below demonstrates how you can work with a custom menu using the TestComplete MSAA subsystem. It types text into a Microsoft Word 2003 document, then copies it and pastes it in the end of the document.

Example

View prerequisites

JavaScript, JScript

function Test()
{
  var p, edit, menu;

  // Obtain the Word process, the document window and its main menu
  p = Sys.Process("WINWORD");
  edit = p.Form("*").Window("_WwF").Panel("*").Panel("Microsoft Word Document");
  menu = p.Form("*").Panel("MsoDockTop").Panel("Menu Bar");

  // Type some text
  edit.Keys("Hello, world!!![Home]");

  // Execute the "Edit | Copy" command of the main menu
  menu.MenuItem("Edit").MenuItem("Copy").DoDefaultAction();

  // Navigate to the end of text
  edit.Keys("^[End][Enter]");

  // Execute the "Edit | Paste" command of the main menu
  menu.MenuItem("Edit").MenuItem("Paste").DoDefaultAction();
}

Python

def Test():

  # Obtain the Word process, the document window and its main menu
  p = Sys.Process("WINWORD")
  edit = p.Form("*").Window("_WwF").Panel("*").Panel("Microsoft Word Document")
  menu = p.Form("*").Panel("MsoDockTop").Panel("Menu Bar")

  # Type some text
  edit.Keys("Hello, world!!![Home]")

  # Execute the "Edit | Copy" command of the main menu
  menu.MenuItem("Edit").MenuItem("Copy").DoDefaultAction()

  # Navigate to the end of text
  edit.Keys("^[End][Enter]")

  # Execute the "Edit | Paste" command of the main menu
  menu.MenuItem("Edit").MenuItem("Paste").DoDefaultAction()

VBScript

Sub Test
  Dim p, edit, menu

  ' Obtain the Word process, the document window and its main menu
  Set p = Sys.Process("WINWORD")
  Set edit = p.Form("*").Window("_WwF").Panel("*").Panel("Microsoft Word Document")
  Set menu = p.Form("*").Panel("MsoDockTop").Panel("Menu Bar")

  ' Type some text
  edit.Keys("Hello, world!!![Home]")

  ' Execute the "Edit | Copy" command of the main menu
  menu.MenuItem("Edit").MenuItem("Copy").DoDefaultAction

  ' Navigate to the end of text
  edit.Keys("^[End][Enter]")

  ' Execute the "Edit | Paste" command of the main menu
  menu.MenuItem("Edit").MenuItem("Paste").DoDefaultAction
End Sub

DelphiScript

procedure Test;
var p, edit, menu;
begin
  // Obtain the Word process, the document window and its main menu
  p := Sys.Process('WINWORD');
  edit := p.Form('*').Window('_WwF').Panel('*').Panel('Microsoft Word Document');
  menu := p.Form('*').Panel('MsoDockTop').Panel('Menu Bar');

  // Type some text
  edit.Keys('Hello, world!!![Home]');

  // Execute the 'Edit | Copy' command of the main menu
  menu.MenuItem('Edit').MenuItem('Copy').DoDefaultAction;

  // Navigate to the end of text
  edit.Keys('^[End][Enter]');

  // Execute the 'Edit | Paste' command of the main menu
  menu.MenuItem('Edit').MenuItem('Paste').DoDefaultAction;
end;

C++Script, C#Script

function Test()
{
  var p, edit, menu;

  // Obtain the Word process, the document window and its main menu
  p = Sys["Process"]("WINWORD");
  edit = p["Form"]("*")["Window"]("_WwF")["Panel"]("*")["Panel"]("Microsoft Word Document");
  menu = p["Form"]("*")["Panel"]("MsoDockTop")["Panel"]("Menu Bar");

  // Type some text
  edit["Keys"]("Hello, world!!![Home]");

  // Execute the "Edit | Copy" command of the main menu
  menu["MenuItem"]("Edit")["MenuItem"]("Copy")["DoDefaultAction"]();

  // Navigate to the end of text
  edit["Keys"]("^[End][Enter]");

  // Execute the "Edit | Paste" command of the main menu
  menu["MenuItem"]("Edit")["MenuItem"]("Paste")["DoDefaultAction"]();
}

See Also

Working With Menus in Desktop Windows Applications
Menu Object
Supported Controls
Using Microsoft Active Accessibility

Highlight search results