How To Click on a Specific Cell of a WebTable Object

To click on a specific cell in a web table, refer to the sample "ClickOnCell" method below. This method is provided AS-IS.

The code below will add the method "ClickOnCell" to the WebTable object. It accepts two arguments, row and column. Both row and column start on the index value of 1.

‘ row and columns start at index 1

Public function myClickOnCell (obj, row, col)

Set oDesc = Description.Create()

oDesc("micclass").Value = "WebElement"

set objs = obj.ChildObjects(oDesc)

count = objs.count – 1

r = 0

c = 0

For i = 0 To count

tag = objs(i).GetROProperty("html tag")

If tag = "TR" Then

r = r +1

c = 0

Else If tag = "TD" or tag = "TH" Then

c = c + 1

End If

‘print tag & " " & " r:" & r & " c:" & c ‘ you can use this line for debugging and understanding purposes

If r = row and c = col Then

oldReplayType = Setting.webpackage("ReplayType")

Setting.webpackage("ReplayType") = 2

Set ibs = objs(i).ChildObjects(Description.Create)

If ibs.count = 0 Then ‘ check for a child object inside the cell

objs(i).click

Else

ibs(0).click

End If

Setting.webpackage("ReplayType") = oldReplayType

Exit Function

End If

Next

End Function

RegisterUserFunc "WebTable", "ClickOnCell", "myClickOnCell", False

‘ Example Usage

Browser("My Browser").Page("My Page").WebTable("My Table").ClickOnCell 3, 2

Advertisements

2 thoughts on “How To Click on a Specific Cell of a WebTable Object

  1. Prashant

    Hi,
    The cell I am trying to click has only “TD” as Tag ,so by using the above function QTP always click on the first row as tag “TR” never comes and r = 0 (initialised).Please suggest a way so that other rows can be clicked.

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s