Parent Property

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

Description

An object can have one parent and any number of child objects. Use an object’s Parent property to get its parent by reference. If the object does not have a parent, the property returns an “empty” object.

Declaration

TestObj.Parent

Read-Only Property Object
TestObj A variable, parameter or expression that specifies a reference to one of the objects listed in the Applies To section

Applies To

All processes, windows, controls and onscreen objects.

View Mode

This property is available in the Object Browser panel and in other panels and dialogs in both Basic and Advanced view modes.

Property Value

The parent object of the current one.

Example

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);
  }
}

See Also

Child Method
Find Method
FindId Method
Exists Property

Highlight search results