TestComplete - Find Child or Find Yourself?

Categories: GUI RecognitionSource codeWeb

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 Find method

We continue with example from the previous post.

What happened when the script clicked on the link? - Web page is reloaded; it’s a new object now.
Before we can operate it, we need to identify it first.

We can go down the hierarchy again starting from Sys or Process objects, but we may re-identify the page using Find method, as in the example below.

 Dim IEProcess, IExplore
 Dim PropNames, PropValues
 Dim Page
 Dim objLink
 'Close browser
 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, 10, True)
 If Not objLink.Exists then
 Exit Sub
 End if
 objLink.Click
 PropNames = Array("objecttype", "url")
 PropValues = Array("page", "http://www.google.ca/advanced_search?hl=en")
 Set Page = Page.Find(PropNames, PropValues, 1, True)
 If Not Page.Exists then
 Exit Sub
 End if

Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported
This work by the author is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported.