Parent. Example

Applies to TestComplete 15.73, last modified on March 04, 2025

The following code performs a click in the center of the screen and determines what process is activated.

JavaScript, JScript

function TestProc()
{
  var p, old_p, s, x, y;
  x = Sys.Desktop.Width / 2;
  y = Sys.Desktop.Height / 2;
  p = Sys.ObjectFromPoint(x, y);
  if (p.Exists)
  {
    while (p.FullName != "Sys")
    {
      old_p = p;
      p = p.Parent;
      if (! p.Exists) break;
    }
  }
  else
    old_p = p;
  if (old_p.Exists && p.Exists)
  {
    s = "Process Name: " + "\r\n" + old_p.ProcessName + "\r\n" +
      "\r\n" + "Process Path: " + "\r\n" + old_p.Path
    Log.Message(old_p.Name, s);
  }
}

Python

def TestProc():
  x = Sys.Desktop.Width / 2
  y = Sys.Desktop.Height / 2
  p = Sys.ObjectFromPoint(x, y)
  if (p.Exists):
    while (p.FullName != "Sys"):
      old_p = p
      p = p.Parent
      if (not p.Exists): break
  else:
    old_p = p
  if (old_p.Exists and p.Exists):
    s = "Process Name: " + "\r\n" + old_p.ProcessName + "\r\n" +\
        "\r\n" + "Process Path: " + "\r\n" + old_p.Path
    Log.Message(old_p.Name, s)

VBScript

Sub TestProc
  x = Sys.Desktop.Width / 2
  y = Sys.Desktop.Height / 2
  Set p = Sys.ObjectFromPoint(x, y)
  If p.Exists Then
    Do
      Set old_p = p
      Set p = p.Parent
      If Not p.Exists Then Exit Do
    Loop Until p.FullName = "Sys"
  Else
    Set old_p = p
  End If
  If old_p.Exists And p.Exists Then
    s = "Process Name: " + vbCrLf + old_p.ProcessName + _
        vbCrLf + vbCrLf + _
        "Process Path: " + vbCrLf + old_p.Path
    Log.Message old_p.Name, s
  End If
End Sub

DelphiScript

procedure TestProc;
var
  p, old_p : OleVariant;
  s, x, y : OleVariant;
begin
  x := Sys.Desktop.Width div 2;
  y := Sys.Desktop.Height div 2;
  p := Sys.ObjectFromPoint(x, y);
  if p.Exists then
  begin
    repeat
      old_p := p;
      p := p.Parent;
      if not p.Exists then
        Break;
    until p.FullName = 'Sys';
  end
  else
    old_p := p;
  if old_p.Exists and p.Exists then
  begin
  s := 'Process Name: ' + #13#10 + old_p.ProcessName + #13#10 +
        #13#10 + 'Process Path: ' + #13#10 + old_p.Path;
    Log.Message(old_p.Name, s);
  end;
end;

C++Script, C#Script

function TestProc()
{
  var x, y, p, old_p, s;
  x = Sys["Desktop"]["Width"] / 2;
  y = Sys["Desktop"]["Height"] / 2;
  p = Sys["ObjectFromPoint"](x, y);
  if (p["Exists"])
    do
    {
      old_p = p;
      p = p["Parent"];
      if (!p["Exists"]) break;
    } while (!(p["FullName"] == "Sys"))
  else
    old_p = p;
  if (p["Exists"])
  {
      s = "Process Name: " + "\r\n" + old_p["ProcessName"] + "\r\n" +
        "Process Path: " + "\r\n" + old_p["Path"];
    Log["Message"](old_p["Name"], s);
  }
}

Highlight search results