Tricentis Tosca 16.0 Released on Feb-2023 ----- UFT has been upgraded from UFT 15.0.1 to UFT One 15.0.2, Beginning at November 2020.

Saturday, 30 March 2019

Determine How Many Child Objects Match a given Description

'The following example uses the ChildObjects method to retrieve a
set of child objects matching the description listed in the function
call and uses the method to display a message indicating how many
objects are found with the specified description: none, one (unique),
or several (not unique).

Public  Function CheckObjectDesription(parent, descr)

Dim oDesc

' Create description object
Set oDesc = Description.Create()
arProps = Split(descr, ",")
For i = 0 To  UBound(arProps)
arProp = Split(arProps(i), ":=")
    If  UBound(arProp) = 1 Then
      PropName = Trim(arProp(0))
      PropValue = arProp(1)
      oDesc(PropName).Value = PropValue
    End  If 
Next 
' Get all child objects with the given description
Set children = parent.ChildObjects(oDesc)

If children.Count = 1 Then
CheckObjectDesription = "Object Unique" 
ElseIf children.Count = 0 Then
CheckObjectDesription = "Object Not Found" 
Else
CheckObjectDesription = "Object Not Unique" 
End  If 
End  Function 

MsgBox CheckObjectDesription(Window("Flight Reservation"),_
"nativeclass:=Button", "text:=&Insert Order")

MsgBox CheckObjectDesription(Desktop, "nativeclass:=Notepad")

No comments:

Post a Comment

Note: only a member of this blog may post a comment.