PopupMenu Property (Window Objects)

Applies to TestComplete 15.69, last modified on November 13, 2024

Description

This property provides a scripting interface to the context (popup, right-click) menu of a window or control.

Declaration

TestObj.PopupMenu

Read-Only Property A Menu object
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:

The top-level windows and controls.

View Mode

To view this property in the Object Browser panel and in other panels and dialogs, activate the Advanced view mode.

Property Value

A Menu object that corresponds to the window's context menu.

Remarks

  • Important: before using the context menu, open it on screen. To do this, call the ClickR method of the desired window or control, or send an Application keypress to it with the Keys method.

  • Using the returned Menu object, you can select items of the context menu. To do this, use the Click method. For more information on available menu actions, see the description of the Menu object.

  • For .NET application users: to access context menus created with the Microsoft MenuStrip Class Library, use the StripPopupMenu property rather than the PopupMenu property.

  • For Java application users: to access context menus of Java windows and controls, use the SwingPopupMenu property.

Example

The following example demonstrates how to use the PopupMenu property in scripts:

JavaScript, JScript

function PopupMenuExample()
{
  // Run Notepad
  WshShell.Run("notepad.exe", SW_SHOWNORMAL);

  // Obtain the edit object
  var p = Sys.Process("NOTEPAD");
  var Edit = p.Window("Notepad").Window("Edit");
  Edit.Keys("White Rabbitttt");

  // Select a portion of the text
  Edit.Keys("![Left]![Left]![Left]");

  // Delete the selected text using the context menu
  Edit.ClickR();
  Edit.PopupMenu.Click("Delete");

  // Select a portion of the text
  Edit.Keys("^a");

  // Cut the selected text using the context menu
  Edit.ClickR();
  Edit.PopupMenu.Click("Cut");

  // Post the clipboard content to the log
  Log.Message(Sys.Clipboard);
}

Python

def PopupMenuExample():
  # Run Notepad 
  WshShell.Run("notepad.exe", SW_SHOWNORMAL)

  # Obtain the edit object
  p = Sys.Process("NOTEPAD")
  Edit = p.Window("Notepad").Window("Edit")
  Edit.Keys("White Rabbitttt")

  # Select a portion of the text
  Edit.Keys("![Left]![Left]![Left]")

  # Delete the selected text using the context menu
  Edit.ClickR()
  Edit.PopupMenu.Click("Delete")

  # Select a portion of the text
  Edit.Keys("^a")

  # Cut the selected text using the context menu
  Edit.ClickR()
  Edit.PopupMenu.Click("Cut")

  # Post the clipboard content to the log
  Log.Message(Sys.Clipboard)

VBScript

Sub PopupMenuExample
  Dim p, Edit
  ' Run Notepad
  WshShell.Run "notepad.exe", SW_SHOWNORMAL

  ' Obtain the edit object and fill it with text
  Set p = Sys.Process("NOTEPAD")
  Set Edit = p.Window("Notepad").Window("Edit")
  Edit.Keys "White Rabbitttt"

  ' Select a portion of the text
  Edit.Keys "![Left]![Left]![Left]"

  ' Delete the selected text using the context menu
  Edit.ClickR
  Edit.PopupMenu.Click "Delete"

  ' Select a portion of the text
  Edit.Keys "^a"

  ' Cut the selected text using the context menu
  Edit.ClickR
  Edit.PopupMenu.Click "Cut"

  ' Post the clipboard content to the log
  Log.Message Sys.Clipboard
End Sub

DelphiScript

procedure PopupMenuExample;
  var p, Edit;
begin
  // Run Notepad
  WshShell.Run('notepad.exe', SW_SHOWNORMAL);

  // Obtain the edit object
  p := Sys.Process('NOTEPAD');
  Edit := p.Window('Notepad').Window('Edit');
  Edit.Keys('White Rabbitttt');

  // Select a portion of the text
  Edit.Keys('![Left]![Left]![Left]');

  // Delete the selected text using the context menu
  Edit.ClickR;
  Edit.PopupMenu.Click('Delete');

  // Select a portion of the text
  Edit.Keys('^a');

  // Cut the selected text using the context menu
  Edit.ClickR;
  Edit.PopupMenu.Click('Cut');

  // Post the clipboard content to the log
  Log.Message(Sys.Clipboard);
end;

C++Script, C#Script

function PopupMenuExample()
{
  // Run Notepad
  WshShell["Run"]("notepad.exe", SW_SHOWNORMAL);

  // Obtain the edit object
  var p = Sys["Process"]("NOTEPAD");
  var Edit = p["Window"]("Notepad")["Window"]("Edit");
  Edit["Keys"]("White Rabbitttt");

  // Select a portion of the text
  Edit["Keys"]("![Left]![Left]![Left]");

  // Delete the selected text using the context menu
  Edit["ClickR"]();
  Edit["PopupMenu"]["Click"]("Delete");

  // Select a portion of the text
  Edit["Keys"]("^a");

  // Cut the selected text using the context menu
  Edit["ClickR"]();
  Edit["PopupMenu"]["Click"]("Cut");

  // Post the clipboard content to the log
  Log["Message"](Sys["Clipboard"]);
 }

See Also

MainMenu Property
StripPopupMenu Property
SwingPopupMenu Property
SystemMenu Property
Simulating Menu Actions

Highlight search results