Function Libraries > Getting the Most Out of UFT Test Objects > Using the UFT Object Model Hierarchy

Using the UFT Object Model Hierarchy

The following example illustrates how to use UFT's test object hierarchy to write better scripts.

If you have a table where you need to click the Details link inside the row that begins with the text Record number 1234, you can use the following code that performs the following:

BeginRowStr = "Record number 1234"
rowCount = Browser("Finance").Page("Finance").WebTable("Records").RowCount
For i=2 to rowCount
	cellData = Browser("Finance").Page("Finance").WebTable("Records").GetCellData (i,1)
	If cellData = BeginRowStr Then
		colCount = Browser("Finance").Page("Finance").WebTable("Records").ColumnCount (i)
		For j=2 to colCount
			cellData = Browser("Finance").Page("Finance").WebTable("Records").GetCellData (i,j)
			If cellData = "Details " Then
				set cellLink = Browser("Finance").Page("Finance").WebTable("Records").ChildItem (i, j, "Link", 0)
				cellLink.Click
				Exit For ' Exit inner loop
			End If
		Next
		Exit For ' Exit outer loop
	End If
Next

Another way to perform this is by using the hierarchical object model of UFT. You can find the correct row by using the description of the row element in the HTML (having the TR html tag), and stating that the element should have the text Record number 1234.*. The constant text will verify that this is the correct row (even if the text is in more then one cell), and the .* will match all the rest of text of that row. After finding the correct row, click the link that has the text Details.

With Browser("Finance").Page("Finance").WebTable("Records")
	.WebElement("html tag:=TR", "innertext:=" & BeginRowStr & ".*").Link("html tag:=A", "innertext:=Details ").Click
End With