3

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!

Alan H.
  • 16,219
  • 17
  • 80
  • 113
K.G.
  • 33
  • 1
  • 1
  • 4

3 Answers3

4

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.

EvereBuddy
  • 205
  • 1
  • 11
0

Try this:

Browser("B").Page("P").WebTable("W").object.rows(rownum-1).cells(colnum-1).Click

Trimble Epic
  • 466
  • 1
  • 3
  • 15
  • 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 – K.G. Jun 21 '16 at 18:23
  • 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! – EvereBuddy Jun 21 '16 at 19:15
0

I was trying to click the first link in my table and this code clicked the item

Set oDesc = Description.Create() 
oDesc("html tag").Value = "A"
Set rc = Browser("B").Page("A").WebTable("html id:=gridTable").ChildObjects(oDesc)
rc(0).Click
'num = rc.Count() 'get the number of link in a page 
'For i=0 to num-1 
'ref = rc(0).GetROProperty("href") 'get the “href”propety of the i th link
'MsgBox ref
'Next

or

Browser("B").Page("A").WebTable("html id:=gridTable").ChildItem(2,8,"Link",0).click

successfully clicks the link I needed

William Humphries
  • 541
  • 1
  • 10
  • 21