TestComplete – Find Child Objects

Posted by Albert Gareev on Nov 11, 2010 | 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 FindAllChildren method

If proper selection of GUI recognition properties is challenge number zero for a beginner automation engineer, the real first one would be recognition of objects without unique set of recognition properties.  As I mentioned, one possible way is to go up (from the object’s stand point) the hierarchy and identify parent or grand parent object that has a unique description. Although it sometimes helps, we may still have a family of objects corresponding to the same recognition properties. In some cases, that is enough, and we can simply retrieve them all in array by using FindAllChildren method (see line 57 in the code example below).

Note, that if no single object were found the returned array is empty (UBound gives -1).

  Dim IEProcess, IExplore
  Dim PropNames, PropValues, arrComboBox
  Dim Page
  Dim objForm, objLink, objComboBox

  'Close browser
  PropNames = Array("processname", "index")
  PropValues = Array("iexplore", 1)
  Set IEProcess = Sys.FindChild(PropNames, PropValues, 1, True)
  If IEProcess.Exists then
  End if 

  'Open browser and navigate to the web-site 
  Set IExplore = TestedApps.iexplore
  IExplore.Params.SimpleParams.CommandLineParameters = ""
  Call IExplore.Run(1, False, 5000) 

  'Find Web Page Object
  PropNames = Array("objecttype", "url")
  PropValues = Array("page", "")
  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

  'Re-identify Web Page
  PropNames = Array("objecttype", "url")
  PropValues = Array("page", "")
  Set Page = Page.Find(PropNames, PropValues, 1, True)
  If Not Page.Exists then
    Exit Sub
  End if

  'Get Web Form Object
  PropNames = Array("objecttype", "outerText")
  PropValues = Array("Form", "Find web pages*")
  Set objForm = Page.FindChild(PropNames, PropValues, 5, True)
  If Not objForm.Exists then
    Exit Sub
  End if
  'Get Child Objects of specified type
  PropNames = Array("tagName")
  PropValues = Array("SELECT")
  arrComboBox = objForm.FindAllChildren(PropNames, PropValues, 10, True)
  'Retrieve object by index
  Set objComboBox = arrComboBox(6) 

  objComboBox.ClickItem("20 results")

  • Leave a Reply

    * Required
    ** Your Email is never shared

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