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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
Dim oDesc,iCounter 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 iCounter=objChkBox.Count For i = 0 to iCounter-1 'Click each checkbox one by one objChkBox(i).Click Next |
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.
Syntax
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.
1 2 3 4 5 |
'Getting 2nd hyperlink from the web table cell which is in the third row and first column. Set objLink=Browser("abc").Page("xyz").WebTable("test").ChildItem(3,1,"Link",1) 'Click on the hyperlink objLink.Click |
ChildItem VS GetCellData
1 2 3 4 5 6 7 |
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) Next Next |
Recommended Posts
- 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