Using the UFT One Object Model Hierarchy

The following example illustrates how to use UFT One'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:

  • Find the correct row by iterating through each row and checking the value of the first cell.
  • After finding the row, iterate through all the cells in the row and find the link you are looking for.
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)
				Exit For ' Exit inner loop
			End If
		Exit For ' Exit outer loop
	End If

Another way to perform this is by using the hierarchical object model of UFT One. 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