Whether it is a web-based application or a windows based application each object (text box, button, list box, checkbox, radio button, hyperlinks, etc) belongs to a class of Object. There are two methods in UFT with the name ChildObjects and ChildItem and people often got confused about their functionalities as the names are quite similar. So let me clear your doubt about the difference between ChildObjects and ChildItem in UFT.
The ChildObjects method is used to retrieve a collection of objects for a specific type of object class. For example, you might come across a scenario wherein you need to count all checkboxes on a page and select all of them. In order to retrieve a collection of the object of a particular class, we need to create a description of the required object. We have to use descriptive programming to create a description of the object.
Difference between ChildObjects and ChildItem in UFT
Example of ChildObjects in UFT
The following code can be used to find all checkboxes on a page and click them one by one.
Set oDesc = Description.Create
oDesc("type").value = "checkbox"
'Find all the checkboxes
Set objChkBox = Browser("abc").Page("xyz").ChildObjects(oDesc)
'iCounter value has the number of all checkboxes in the web page
For i = 0 to iCounter-1
'Click each checkbox one by one
Example of ChildItem in UFT
The ChildItem method is used to access the required child object from a web table cell without using a description object. Unlike ChildObjects, it returns only one object at a time.
object.ChildItem(Row, Column, MicClass, Index) where Index starts from 0.
Example: There is a web table and each table cell is having multiple hyperlinks inside it. Suppose you have to click the second hyperlink in the third row and first column of a web table cell. The following code can be used.
'Getting 2nd hyperlink from the web table cell which is in the third row and first column.
'Click on the hyperlink
ChildItem VS GetCellData
iRowCount = Browser("abc").Page("xyz").WebTable("test").RowCount
iColumnCount = Browser("abc").Page("xyz").WebTable("test").ColumnCount
For i = 1 to iRowCount ' Iterating all rows
For j = 1 to iColumnCount 'Iterating all columns
Print Browser("abc").Page("xyz").WebTable("test").GetCellData (i,j)
- How to Use XPath in UFT One To Identify Web-Based Objects
- Web Table Methods in UFT With Example
- All You Need to Know About Object Identification in UFT
- How to Record a Script in Chrome Browser in UFT
- How to Load Function Libraries in UFT
- UFT Reporter Object Methods that You Don’t Know
- UFT Report | Run Result and ALM Connection
- Transactions in UFT with Example
- How to Use Data Driver for Automated Parameterization in UFT