Selecting Menu Items. Example

Applies to TestComplete 15.47, last modified on January 20, 2023

This example demonstrates how you can operate application menus from scripts. It activates the Open File dialog within the Notepad application, which must be running.

JavaScript, JScript

function TestProc()
{
  var p, w;

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

  if (w.Exists)
    w.MainMenu.Click("File|Open...");
}

Python

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

  if (w.Exists):
    w.MainMenu.Click("File|Open...")

VBScript

Sub TestProc
  Dim p, w

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

  If w.Exists Then
    w.MainMenu.Click("File|Open...")
  End If
End Sub

DelphiScript

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

  if w.Exists then
    w.MainMenu.Click('File|Open...');
end;

C++Script, C#Script

function TestProc()
{
  var p, w;

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

  if (w["Exists"])
    w["MainMenu"]["Click"]("File|Open...");
}

See Also

Working With Menus in Desktop Windows Applications
Simulating Menu Actions

Highlight search results