Working with Child Objects – Part 1 - Description Programming, Count ChildObjects, Enumerating ChildObjects
In this post we will discuss:
- Count the number of check boxes available in the webpage
- Check All Checkboxes in the webpage
You can copy and pate the below code in QTP and run the script.
' - - - - - - - - - - Count & check the number of check boxes available in the webpage ' - - - - - - - - - -
SystemUtil.Run "iexplore.exe", “http://www.onestopsoftwaretesting.com/qtptest.html”
'Create a Description object
Set dpAllChk = Description.Create
'Define the class of the above created Description object
dpAllChk("micclass").value = "WebCheckBox"
'Getting all the textboxes
Set Allchk = Browser("Browser").Page("Page").childobjects(dpAllChk)
Allchk(0).set "ON"
'count all the textboxes
chkcount = Allchk.Count
msgbox chkcount & " check boxes are available in the webpage"
'Check all textboxes in the webpage
icounter = Allchk.Count -1
For i = 0 to icounter
Set otext = Allchk.item(i) ‘item property - Exposes a specified item from a collection.
otext.set "ON"
Next
' - - - - - - - - - - - - - - - - End - - - - - - - - - - - - - - - -