Unified Functional Testing Practitioners Forum

QTP How to select a row in a Webtable

Adriana S.
New Member.

QTP How to select a row in a Webtable


I have checked in this forum if somebody have reported this problem, but I could not find any.
There is my issue, I have a webtable and I need to select a row where my two input values match (each value in different columns). Once I find out the row I need to in the row and it will be hightlited.

I got the step where I have the row number,now my problem is how to select the row if I cannot use SelectRow function.
I tried to use ChildItem, but I could not select the cell or the row.

Please if somebody have any idea, it will welcome.

Here is the example of my code:

set objNew= Browser("Hazardous Materials - Origin in USA Mixed").Page("Electronic Customer").Frame("SiMixHazPickListFrame").WebTable("Select a product").ChildItem(4,1,"WebElement",0)



Regular Contributor.

Re: QTP How to select a row in a Webtable


try this

your row="2"
ypur column ="2"

Set obj=Browser("browser").page("page").Frame("frame").webtable("webtable").object


Re: QTP How to select a row in a Webtable

I have a similar issue. I need to click(or drag) the object contained in a particular cell. Tried with the below ways:

row = 3
colum = 3
Set obj = Browser("Profile Security Role").Page("Profile Security Role").WebTable("ROLE_ID").Object
obj.rows(row - 1).cells(colum - 1).Click

Set objObj = Browser("Profile Security Role").Page("Profile Security Role").WebTable("ROLE_ID").ChildItem(2, 2, "WebElement", 0)



But no luck. Please help

New Member.

Re: QTP How to select a row in a Webtable

Even It does not work for me too :( I get below error. Please help if there is some other way 



Trudy Claspill
Acclaimed Contributor.

Re: QTP How to select a row in a Webtable

You will probably get more relevant answers if you repost this question in the forum specifically for QTP.
[If this post solves or helps solve your issue, mark the thread as solved and give KUDOS to the author for their assistance.]

(Opinions expressed in my postings are mine alone, and do not reflect the opinions of my employer.No warranties express or implied for any solution/suggestion posted.)
Trusted Contributor.

Re: QTP How to select a row in a Webtable



the rows in HTML table are usually "selected" using CSS class.

See Javascript solution

You just use a tableRow variable instead of document.getElementById("MyElement").

The tableRow variable you have to set to a TR HTML object:

Set tabObj = Browser("Model On Demand").Page("Model On Demand").Frame("Frame").WebTable("Table_Projects")

Set rows = tabObj.Object.rows 'I did not try it, depends on type conversion of rows property

iterate rows, set tableRow and finally set the "selected" CSS class




Micro Focus Expert

Re: QTP How to select a row in a Webtable



Maybe the problem is with clicking this WebElement. What does it represent (or contain) exactly? It would best if you show it in a screenshot.


Here are some possible workarounds for the WebElement clicking:
1.            Change the replay type from within script:
Setting.webpackage("ReplayType") = 2
Setting.webpackage("ReplayType") = 1
2.            Use FireEvent (load also Java add-in)
If the object is using the click event to trigger any JavaScript Action you could try to execute the event by using the following statement.
Then you could try to perform the click action:
3.            Send Keys
Sendkeys emulate the keyboard behavior, so please try to reproduce the “Press key down” action using send keys. For more information please refers to the article below:
How to send a key command to an object: http://support.openview.hp.com/selfsolve/document/KM183695
Set obj = CreateObject("WScript.Shell") ' Creates object we can use to call SendKeys
obj.SendKeys "Hello" ' Types "Hello"
obj.SendKeys "{TAB}" ' sends the tab key
obj.SendKeys "{ENTER}" ' sends the enter key
obj.SendKeys "{UP}" ' sends the up arrow key
obj.SendKeys "{DOWN}" ' sends the down arrow key
obj.SendKeys "{LEFT}" ' sends the left arrow key
obj.SendKeys "{RIGHT}" ' sends the right arrow key
Set obj = Nothing ' destroys object (no longer needed once typing is done)
From the documentation, you can also see that all the possible keys can be utilized including (ALT, CTRL, and SHIFT) keys as well.
This can be extremely helpful for workarounds using keyboard events where DeviceReplay has limitations.
4.            Use Device Replay feature.
set obj = Browser("Browser").Page("Page").WebElement("WebElement")
x = obj.GetROPRoperty("abs_x")
x = x + obj.GetROPRoperty("width")/2
y = obj.GetROPRoperty("abs_y")
y = y + obj.GetROPRoperty("height")/2
Set devicereplay = CreateObject("Mercury.DeviceReplay")
devicereplay.MouseClick x, y, 0
Set devicereplay = Nothing
set obj = nothing
Please check following article for details: http://support.openview.hp.com/selfsolve/document/KM184330



“HP Support
If you find that this or any post resolves your issue, please be sure to mark it as an accepted solution.”

Re: QTP How to select a row in a Webtable

I was struggling with it and finally method #4 worked. Thank you very much.

New Member.

Re: QTP How to select a row in a Webtable



You can use the below code for selecting a row in webTable




where rownumber is your row to be selected.