Tuesday, April 6, 2010

How To Retrive Value from Webelement in QTP

Today I got a problem from one of my reader regarding "Retriving value from Webelement in QTP"...
I have a question to you regarding an issue we faced today.

Scenerio is:-

1)We have an object as WebElement whose value is dynamically changing.For example,say i want to retrieve a policy number.When i added that object and retrieve with GETROPROPERTY,it is retrieving only one value which is added in the OR.For the next iteration it is throwing an error saying cannot find object.

In this scenerio, we use regular expression,but using that it didnt helped.What are the other way to solve this issue?Please help me regarding this.

If the value of the webelement changes then getROProperty sometimes do not work ...
As you are capturing policy number. So i assume that it changes from policy to policy.
I dont know your application. I am assuming it is on Web and written on any of the web language.
I am taking an example of Gmail home page where the third space "Lots of space" is getting changed time to time.

So if you add this and try to use the function getROProperty ,then the problem you will face is like this only...

The alternative approaches are:

1.Please try to include additional properties inorder to make the webelement get identified as they could have added extra properties.Spy the object get the porperties for the extra properties
2.You can update the webelement from the application into the object repository and make sure class of the object is not changed.


Browser("Google").Navigate http://www.google.co.in/
msgbox Browser("Google").Page("Gmail: Email from Google").WebElement("place").GetROProperty("innertext")

3. if the above approah does not give you the required result please try this...
Set childobjdes = Description.Create()

childobjdes("outertext").value =".*[A-Za-z0-9].*"
Set oWebElement = Browser("Google").Page("Gmail: Email from Google")
Set oStyle = oWebElement.Childobjects(childobjdes)
msgbox oStyle.count
For i=o to oStyle.count-1
msgbox i &"->" & oStyle(i).getROProperty("outertext")

So you can exactly get the Element no and track your required no.

4. If all the above code does not give you the required result then you can actually go for this concept.
If you really see the webpage...this is a table structure. even QTP identifies those tables...the values of this space or policy number (for your case) is coming to cell of a table.
Now you need to add these tables to your OR. atleast the last table..
r= Browser("Gmail: Email from Google").Page("Gmail: Email from Google_2").WebTable("Less spamKeep unwanted").RowCount

c= Browser("Gmail: Email from Google").Page("Gmail: Email from Google_2").WebTable("Less spamKeep unwanted").ColumnCount(r)
For i=1 to r
For j=1 to c
msgbox Browser("Gmail: Email from Google").Page("Gmail: Email from Google_2").WebTable("Less spamKeep unwanted").GetCellData(i,j)

From the string you can find the policy number.

Hope this will help you.
Let me know if you need any other help.


  1. Hi Animesh,
    Thanks a lot and indeed u explained well.Yes,its a web applicsation.I will let you know if it works..

  2. Thanks.
    for the posting

  3. you are most welcome. do let me know if you have any other problem..

  4. Hi,

    Hope you are doing good.
    My name is viju nambiar, working as softtware test engineer in kerala.
    I have 3+ experience in manual testing field.
    Now am planning to do certification and learning automation tools.
    Which certification is good?
    Now ISTQB is in my mind.
    So if you have more materials regarding this, please send me.
    Your blog is very usefull.
    Advance thanks.


  5. Hi Vijunambiar,
    Sure...I will send you all the docs what i have...please share your email id.

    Again ISTQB is good for you.Even i passed my ISTQB in 4 yrs...so pls go for it.



Tech News

Don't miss new products

Subscribe here to get our newsletter in your inbox, it is safe and EASY!

Ask QTP © 2014 - Designed by Templateism.com, Plugins By MyBloggerLab.com