Enumerating ChildObjects - QTP

QTP provides the ChildObjects method which is used to enumerate child objects. To enumerate all the textboxes on a page we can use the following code

'Create a description object
Set dpAllTxt = Description.Create
'Set the description for WebEdit only

dpAllTxt("micclass"). value = "webEdit"
'Get all the objects raacthing the description
Set allTextboxes = Browser("Google").Page("Google").ChildObjects(dpAllTxt) 'Loop through all of them
iCount = allTextboxes.Count - 1
For i = 0 to iCount
Set oTxt = allTextboxes.item(i)
oTxt.Set "This is Text box #" & (i+1)

ChildObjects enumerates all the child objects when we pass it an empty description object:

'Create a description object
Set dpAHChilds = Description.Create
'Get all the objects on the page as a blank description is used Set allChilds = Browser
("Google") .Page ("Google"). ChildObjects (dpAllChilds)
iCount = allChilds.Count - 1
'Loop through all the objects on the page
For i = 0 To iCount

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

QTP Topics