Finding Several Images Within a Window

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

Assuming the currently active window is a tree view, this code will find each + button in it and click it.

JavaScript

function TestProc()
{
  var w, y, Rect;
  w = Sys.Desktop.ActiveWindow();
  w = w.Window("MyTreeView", "*");
  y = 0;
  for (;;)
  {
    Rect = Regions.FindRegion("PlusButton", w, 0, y);
    if (strictEqual(Rect, null))
      break;
    y = Rect.Bottom;
    w.Click(Rect.Left + Rect.Width / 2, Rect.Top + Rect.Height / 2);
    // wait a little for the tree list to expand its nodes
    aqUtils.Delay(2000);
    Rect = null;
  }
}

JScript

function TestProc()
{
  var w, y, Rect;
  w = Sys.Desktop.ActiveWindow();
  w = w.Window("MyTreeView", "*");
  y = 0;
  for (;;)
  {
    Rect = Regions.FindRegion("PlusButton", w, 0, y);
    if (Rect == null)
      break;
    y = Rect.Bottom;
    w.Click(Rect.Left + Rect.Width / 2, Rect.Top + Rect.Height / 2);
    // wait a little for the tree list to expand its nodes
    aqUtils.Delay(2000);
    Rect = null;
  }
}

Python

def TestProc():
  w = Sys.Desktop.ActiveWindow()
  w = w.Window("MyTreeView", "*")
  y = 0
  while True:
    Rect = Regions.FindRegion("PlusButton", w, 0, y)
    if (Rect == None):
      break
    y = Rect.Bottom
    w.Click(Rect.Left + Rect.Width / 2, Rect.Top + Rect.Height / 2)
    # wait a little for the tree list to expand its nodes
    aqUtils.Delay(2000)
    Rect = None

VBScript

Sub TestProc
  Set w = Sys.Desktop.ActiveWindow.Window("MyTreeView", "*")
  y = 0
  Do
    Set Rect = Regions.FindRegion("PlusButton", w, 0, y)
    If Rect Is Nothing Then Exit Do
    y = Rect.Bottom
    Call w.Click(Rect.Left + Rect.Width / 2, Rect.Top + Rect.Height / 2)
    ' wait a little for the tree list to expand its nodes
    aqUtils.Delay 2000
    Set Rect = Nothing
  Loop
End Sub

DelphiScript

procedure TestProc;
var
  w, y, Rect : OleVariant;
begin
  w := Sys.Desktop.ActiveWindow.Window('MyTreeView', '*');
  y := 0;
  repeat
    Rect := Regions.FindRegion('PlusButton', w, 0, y);
    if Rect = nil then
      break;
    y := Rect.Bottom;
    w.Click(Rect.Left + Rect.Width div 2, Rect.Top + Rect.Height div 2);
    // wait a little for the tree list to expand its nodes
    aqUtils.Delay(2000);
    Rect := nil;
  until False;
end;

C++Script, C#Script

function TestProc()
{
  var w, y;
  w = Sys["Desktop"]["ActiveWindow"]();
  w = w["Window"]("SysTreeView32");
  y = 0;
  for (;;)
  {
    Rect = Regions["FindRegion"]("PlusButton", w, 0, y);
    if (Rect == null)
      break;
    y = Rect["Bottom"];
    w["Click"](Rect["Left"] + Rect["Width"] / 2, Rect["Top"] + Rect["Height"] / 2);
    // wait a little for the tree list to expand its nodes
    aqUtils["Delay"](2000);
    Rect = null;
  }
}

Highlight search results