TestComplete – Run-time GUI recognition
Parent page: GUI Recognition with TestComplete
TestComplete provides a whole set of run-time GUI recognition functionalities, based, however, on the same approach: recognition by property values and/or location of the object in internal hierarchy.
Today’s post is about FindChild method
Let’s start with the example.
Dim IEProcess, IExplore Dim PropNames, PropValues Dim Page Dim objLink 'Close browser window PropNames = Array("processname", "index") PropValues = Array("iexplore", 1) Set IEProcess = Sys.FindChild(PropNames, PropValues, 1, True) If IEProcess.Exists then IEProcess.Close(10000) End if 'Open browser and navigate to the web-site Set IExplore = TestedApps.iexplore IExplore.Params.SimpleParams.CommandLineParameters = "http://www.google.ca/" Call IExplore.Run(1, False, 5000) 'Find Web Page Object PropNames = Array("objecttype", "url") PropValues = Array("page", "http://www.google.ca/") Set Page = Sys.Process("iexplore").FindChild(PropNames, PropValues, 1, True) If Not Page.Exists then Exit Sub End if 'Find Web Link Object PropNames = Array("tagName", "namePropStr") PropValues = Array("A", "advanced_search*") Set objLink = Page.FindChild(PropNames, PropValues, 4, True) If Not objLink.Exists then Exit Sub End if 'Click on the link objLink.Click
Note highlighted lines: this is where object recognition properties are defined. As you see from lines ## 7,8, TestComplete supports not only GUI objects recognition, but recognition of any object in hierarchy, including processes.
The third parameter of FindChild method is depth, which is defined by position of the object in hierarchy. In our example, the full path string to the link from the root is:
Sys.Process(“iexplore”).Page(“http://www.google.ca/”).Form(“f”).Table(0).Cell(0, 2).Link(0)
Which means, counting from the Sys object, depth of the link is 6. Counting from the Page object, the depth is 4.
Note, that we specify max depth to search within. An object could be found “higher” in the hierarchy; but if it’s “lower” than the depth specified, then search won’t be successful.
If an object has unique identification properties in wide context, middle step may be omitted, as in the example below.
Dim IEProcess, IExplore Dim PropNames, PropValues Dim objLink 'Close browser window PropNames = Array("processname", "index") PropValues = Array("iexplore", 1) Set IEProcess = Sys.FindChild(PropNames, PropValues, 1, True) If IEProcess.Exists then IEProcess.Close(10000) End if 'Open browser and navigate to the web-site Set IExplore = TestedApps.iexplore IExplore.Params.SimpleParams.CommandLineParameters = "http://www.google.ca/" Call IExplore.Run(1, False, 5000) 'Find Web Link Object PropNames = Array("tagName", "namePropStr") PropValues = Array("A", "advanced_search*") Set objLink = Sys.Process("iexplore").FindChild(PropNames, PropValues, 10, True) If Not objLink.Exists then Exit Sub End if objLink.Click