I am writing a script which tests a C++ application and am currently experiencing problems with ObjectIndexes. ListViews Objects are recognised by Robot using their ObjectIndex, but the ObjectIndex value is not consistent every time I run the script. Bad!!

I have tried changing the Object Recognition Order but this has not worked; the recognition method which can also be used is ObjectId but this also changes.

Does anyone have some idea as to why the ObjectIndex may be changing? One previous post suggested "Forms are (re)created from scratch, and controls are not added in exactly the same sequence as before (or not all the same controls)." If this is the case, how could this problem be overcome i.e. producing the forms in exactly the same order?

My workaround is to create an inventory of all controls on the form (using SQAGetChildren) and retrieve the current/new ObjectIndex for each listview control "on the fly". This solution works but may prove to be maintenance heavy in the long run. See below for the script.

Does anyone have a better solution to this problem?

'$Include "sqautil.sbh"

Sub Main
Window SetContext, "Caption=Contact Centre", ""

Dim Result As Integer
Dim ChildRec() As String
Dim Identifier as String
Dim itemsInList as variant
Dim itemCount as integer
Result = sqaPass

If SQAGetChildren("\;Type=Window;Caption=Contact Centre", ChildRec) = sqaSuccess Then

Dim ObjectType, Length, Height
Dim n As Integer

For n = 0 To UBound(ChildRec)
SQAGetProperty ChildRec(n), "ObjectType", ObjectType
If ObjectType = "ListView" Then
SQAGetProperty ChildRec(n), "Width", Length
SQAGetProperty ChildRec(n), "Height", Height
If Length = 666 and Height = 426 Then
SQALogMessage sqaPass,"Test for ListView","Object """+ChildRec(n)+""""
Result = sqaPass
End If
End If

Next n
End If

'msgbox Identifier
itemCount = SQAGetPropertyAsString(Identifier, "ItemCount" , itemsInList)
If itemCount=sqaSuccess and itemsInList=1 then
SQAlogMessage sqaPASS, "No. Items In List Correct", ""
SQAlogMessage sqaFAIL, "No. Items In List Incorrect", ""
End IF

End Sub