When multiple objects in an application have the same property?

There might be situations when multiple objects in AUT have the same property and hence you will not be able to identity the objects uniquely. For example, there are five list boxes in a web page, which have identical properties. In such situation, QTP will not be identifying each of the list boxes uniquely.
This can be done using Description Object and ChildObjects. Description object creates a Properties collection object. It has a method 'Create'. This method creates an empty description object in which you can add collection of properties and values in order to specify the description object in place of a test object.
ChildObjects returns the collection of child objects within the object.

If in the above example if the five List boxes have the same name, html id and class. T
o identify each of the listbox uniquely,

Set obj = Description.create()
obj("micclass").value = "WebList"
obj("class").value= "abc"
obj("name").value = "List1"
obj("html id").value = "htm1"
Set newObj = Browser("...").page("...").ChildObjects(obj)


Here instead of specifying each of the Listboxes by its properties, we identify them as newObj(0), newObj(1), newObj(2), newObj(3)

so, to select an item "abc' from third List box in this browser

Browser("...").page("...").newObj(2).Select "abc"

To display the number of similar child Objects with the same description

MsgBox newObj.Count

No comments: