Selecting Menu Items. Example

Applies to TestComplete 14.93, last modified on October 12, 2021

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
Simulating Menu Actions

Highlight search results