While automating an application, sometimes we have a number of homogeneous objects having one or more properties with same value present in a page and we have to perform a specific operation on all the objects in that page. Adding all the objects to the object repository means increase in script size and it gets worse with a large number of objects. Another disadvantage of this approach is that when more objects are added to the page, we have to add those to the object repository. There is a much better way to solving this problem. We can create a collection of objects those satisfy some specific condition(s) and perform the operations on the required objects. It solves both the purpose of not adding a single object to object repository and it can also include all the objects introduced at a later point of time. Now let us think about a situation where this can be useful. Suppose there is a Setup page with a number of fields. There are 2 check boxes aside each field named as “Hidden” and “Mandatory”. The user has the option to make any field “Hidden” by ticking the “Hidden” checkbox, “Optional” by unticking both the checkboxes and “Mandatory” by ticking the “Mandatory” checkbox. When the “Mandatory” checkbox for a particular field is checked, the “Hidden” checkbox for that field is disabled and vice versa. In a way to be able to tick the checkbox that is disabled, the other checkbox needs to be unticked first. Now suppose our script requires some changes in the Setup page (Some fields need to be made Optional, some Hidden and some Mandatory), but we are not sure which filed is in which state. So for that we need to untick all the checkboxes first. Following example shows how we can achieve this.
|
Set webChkBox = Description.Create // Create an instance of Description object
webChkBox(“micclass”).Value = “WebCheckBox” // Class type is assigned to the Description object
webChkBox(“name”).Value = “Mandatory|Hidden” // Objects of “WebCheckBox” type whose names are either Mandatory or Hidden
Set allWebChkBoxes = Browser(“BrowserName’).Page(“PageName”).ChildObjects(webChkBox)// Collection of all the check boxes with the specified properties present in a page
For counter = 0 To allWebChkBoxes.Count – 1
allWebChkBoxes(counter).Set “OFF” // Untick all the checkboxes
Next
We can be more specific on objects by filtering the collection by more properties.
|