Pasting Text via the Context Menu

Applies to TestComplete 14.70, last modified on April 22, 2021

The following procedure pastes text from the Clipboard into Notepad, using the Paste item from the context menu of Notepad, which must be running.

JavaScript, JScript

function TestProc()
{
  var p, w, w2;

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

  if (w.Exists)
  {
    w.Maximize();
    w2 = w.Window("Edit");
    w2.ClickR(Sys.Desktop.MouseX, Sys.Desktop.MouseY);
    w.PopupMenu.Click("Paste");
  }
}

Python

def TestProc():

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

  if (w.Exists):
    w.Maximize()
    w2 = w.Window("Edit")
    w2.ClickR(Sys.Desktop.MouseX, Sys.Desktop.MouseY)
    w.PopupMenu.Click("Paste")

VBScript

Sub TestProc
  Dim p, w, w2

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

  If w.Exists Then
    w.Maximize
    Set w2 = w.Window("Edit")
    Call w2.ClickR(Sys.Desktop.MouseX, Sys.Desktop.MouseY)
    w.PopupMenu.Click("Paste")
  End If
End Sub

DelphiScript

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

  if w.Exists then
  begin
    w.Maximize;
    w2 := w.Window('Edit');
    w2.ClickR(Sys.Desktop.MouseX, Sys.Desktop.MouseY);
    w.PopupMenu.Click('Paste');
  end;
end;

C++Script, C#Script

function TestProc()
{
  var p, w, w2;

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

  if (w["Exists"])
  {
    w["Maximize"]();
    w2 = w["Window"]("Edit");
    w2["ClickR"](Sys["Desktop"]["MouseX"], Sys["Desktop"]["MouseY"]);
    w["PopupMenu"]["Click"]("Paste");
  }
}

See Also

Working With Menus
Simulating Menu Actions

Highlight search results