Reputation: 203
I have this code that clicks on first row and column one just fine.
Set oExcptnDetail = Description.Create
oExcptnDetail("micclass").value = "WebElement"
oExcptnDetail("html tag").value = "TD"
Set chobj=Browser("").Page("").WebTable("Code").ChildObjects(oExcptnDetail)
chobj(0).Click
How can I click on a specific row using above code?
I used childitem that did not work.
set objLink = Browser("bb").Page("bb").WebTable("Name_2").ChildItem(4, 1, "WebElement",0)
Update 1
I tried the below code. It did not click row 3 col 1.
Set desc = Description.Create
desc("html tag").value = "TR"
Set rows = table.ChildObjects(desc)
desc("html tag").value = "TD"
Set cells = rows(3).ChildObjects(desc)
Set TableCell = cells(1)
Browser("").Page("").WebTable(TableCell).Click
Upvotes: 1
Views: 1714
Reputation: 114695
UFT's ChildItem
function returns elements contained within cells, this means that it won't return the TD
that is the cell, only its descendants.
In order to get the cell itself you should use WebTable.Cell
, this is a relatively new functionality in UFT and you may not have it. If you don't you should be able to write a helper function like this (note I'm writing this without checking it out, it may need additional work and error handling):
Function TableCell(table, nRow, nCol)
Set desc = Description.Create
desc("html tag").value = "TR" ' Or "T[RH]" to capture TH too
Set rows = table.ChildObjects(desc)
desc("html tag").value = "TD"
Set cells = rows(nRow).ChildObjects(desc)
Set TableCell = cells(nCol)
End Function
Then you can use RegisterUserFunc
to use it as WebTable.Cell
if you wish.
Then you can use it thus:
TableCell(Browser("").Page("").WebTable("Code"), 4, 1).Click
Or if you used RegisterUserFunc
to register it as Cell
:
Browser("").Page("").WebTable("Code").Cell(4, 1).Click
Upvotes: 1