Clicking on specific row in a WebTable using UFT/QTP

31,886

It happened with me as well. When I researched, I found in some of the old HP blogs that ChildItem method does not works correctly with WEBElement, but that was for QTP 9.0, and I was using 12.02.Anyhow, I can't figure out why its happening, and ended up using the following -

Set oExcptnDetail = Description.Create
oExcptnDetail("micclass").value = "WebElement"
oExcptnDetail("html tag").value = "TD"
Set chobj=Browser("").Page("").WebTable("Code").ChildObjects(oExcptnDetail)
chobj(0).Click 

On a side note, in order to check a webelement/link exist in a certain row and column, use the following.

 Browser("B").Page("P").WebTable("W").ChildItemCount(2,2,"WebElement")

Getcell data will return you anything that is in the desired row and column irrespective of what it is (link,webelement etc) and hence your assumption of if loop will go wrong.

Share:
31,886
K.G.
Author by

K.G.

Updated on September 28, 2020

Comments

  • K.G.
    K.G. over 3 years

    I am having hard time clicking specific row in a Web Table. My code finding proper row, but when I use Child Item method it complains that Object is not found. Here is my code:

    Desc = "Record to click"
    
    If Browser("B").Page("P").WebTable("W").exist(10) Then
    
        totalRows = Browser("B").Page("P").WebTable("W").RowCount()
        For RowNum = 1 To totalRows
            If aDesc = Browser("B").Page("P").WebTable("W").GetCellData(RowNum,2) Then
                Browser("B").Page("P").WebTable("W").ChildItem(RowNum,2,"WebElement",0).click
            End If
        Next
    End If
    

    I spied on the value in the row it is Web Element, I tried to use Link- didn't work. Also I tried to Child Item(aDesc,2,"WebElement",0)- didn't work either. I used 0 for the index because there is only one element in the row - simple text. I keep getting this error in many other tests. On rare occasion this approach works in some tests, but most of the time it complains for absence of object.
    Thank you very much for your help!

  • Motti
    Motti about 8 years
    The reasoning behind this is that ChildItem should return children of the cell but not the cell itself.
  • K.G.
    K.G. about 8 years
    Thank you Harman, your code using ChildObjects has worked. But now I have another issue. I have a webtable on the screen and I need verify values in the table, visually I see there is 10 columns and 5 rows, but when I spy on the table the cols parameter (for columns) has value 1. I can't understand why this table has 1 column when there is 10 columns
  • EvereBuddy
    EvereBuddy about 8 years
    See what the following gives you---> Colcount =Browser("B").Page("P").WebTable("W").ColumnCount -------------msgbox Colcount , if it returns 10 then you can use Getcelldata to get the items of a particular row and column irrespective of what object spy is showing you!
  • William Humphries
    William Humphries over 5 years
    Thank you, worked great for me. All I had to do was modify ("html tag").value = "TD" with "A"