As you can see that the Delete button is located inside the webtable. Now, we are going use the Object Repository to store the object. To achieve that, I started recording the script. While recording I click on any of the Delete button. As a result, QTP automatically saved all the objects it has interacted with. Then I change the Title of the browser to broWCP and Page to pgWCP in the OR. Below is the code.
Dim iRow, iCol, sRow, sButton
Dim bStatus:bStatus=False
sAccount="Acc Nick Name" 'Account Name to delete
iRow= Browser("broWCP").Page("pgWCP").WebTable("HSA Custodian").RowCount 'Find out the total row
iCol= Browser("broWCP").Page("pgWCP").WebTable("HSA Custodian").ColumnCount(iRow) 'Find the total Column
For i=1 to iRow 'get the row no where the target item exists
If Browser("broWCP").Page("pgWCP").WebTable("HSA Custodian").GetCellData(i,3)= sAccount Then
sRow=i
bStatus=True
Exit for
Else
bStatus=False
End If
Next
If bStatus Then
Set sButton=Browser("broWCP").Page("pgWCP").WebTable("HSA Custodian").ChildItem(sRow, iCol, "WebButton", sRow-2)
sButton.Highlight
sButton.click
Else
Msgbox "Could not find the item"
End IF
We know that the field "Account Nickname" exits on the 3rd column of the table. We have also identified that all the "Delete" buttons located in the last column of the table, hence we used whatever value is assigned to
iCol. Later part "
sRow -2" is due to the fact that index starts with "0" and our first row of the table contains the column heading. Hence, we need to subtract 2 from
sRow. Last argument of childitem method is the index no.
This is how we can handle dynamic button inside a WebTable. Hope you enjoyed learning this fact.