The following example illustrates how to use QuickTest Professional's test object hierarchy to write better scripts.
If you have a table where you need to click on 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
cellData = Browser("Finance").Page("Finance").WebTable("Records").GetCellData (i,1)
If cellData = BeginRowStr Then
colCount = Browser("Finance").Page("Finance").WebTable("Records").ColumnCount (i)
cellData = Browser("Finance").Page("Finance").WebTable("Records").GetCellData (i,j)
set cellLink = Browser("Finance").Page("Finance").WebTable("Records").ChildItem (i, j, "Link", 0)
Another way to perform this is by using the hierarchical object model of QuickTest Professional.
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 on 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
No comments:
Post a Comment