Highlighting Objects from the Same Class

The code below helps resolve the Object not unique problem. It highlights all the runtime objects that have the same description. The following example can be found in the HighLightObjects.vbs and HighLightObject.py files located in the <Installdir>\CodeSamplesPlus folder.

VBScript sample

Copy code
' Sample usage: Assume that WinButton description is not unique
HighlightAll Dialog("Options").WinButton("Browse")

' Routine that highlights all the objects
Sub HighlightAll(TestObject)
    Dim Parent, Desc, Props, PropsCount, MaxIndex, i, Objs 
    If IsEmpty(TestObject.GetTOProperty("parent")) Then 
        Set Parent = Desktop 
    Else 
        Set Parent = TestObject.GetTOProperty("parent"
    End If 
    Set Desc = Description.Create 
    Set Props = TestObject.GetTOProperties 
    PropsCount = Props.Count - 1 
    For i = 0 to PropsCount 
        Desc(Props(i).Name).Value = Props(i).Value 
    Next 
    Set Objs = Parent.ChildObjects(Desc) 
    MaxIndex= Objs.Count - 1 
    For i = 0 to MaxIndex 
        Objs.Item(i).Highlight 
    Next
End Sub

Python sample

Copy code
def highlight_all():
    row_count = Browser("Test Table | Practice").Page("Test Table | Practice").WebTable("ID").RowCount()
    for i in range(2, row_count + 1):
        obj_count = Browser("Test Table | Practice").Page("Test Table | Practice").WebTable("ID").ChildObjects().Count()
        for j in range(0, obj_count):
            Browser("Test Table | Practice").Page("Test Table | Practice").WebTable("ID").ChildObjects().Item(j).Highlight()


highlight_all()