How To Retrieve Value from Webelement in QTP/UFT?

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.
How To Retrieve Value from Webelement in QTP/UFT?
How To Retrieve Value from Webelement in QTP/UFT?
So if you add this and try to use the function getROProperty ,then the problem you will face is like this only…
How To Retrieve Value from Webelement in QTP/UFT?
How To Retrieve Value from Webelement in QTP/UFT?

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.
How To Retrieve Value from Webelement in QTP/UFT?
How To Retrieve Value from Webelement in QTP/UFT?

Browser("Google").Page("Google").Sync
Browser("Google").Navigate http://www.google.co.in/
Browser("Google").Page("Google").Link("Gmail").Click
msgbox Browser("Google").Page("Gmail: Email from Google").WebElement("place").GetROProperty("innertext")
How To Retrieve Value from Webelement in QTP/UFT?
How To Retrieve Value from Webelement in QTP/UFT?

3. if the above approah does not give you the required result please try this…

 
Code:

Set childobjdes = Description.Create()
childobjdes("micclass").value="WebElement"
childobjdes("innerhtml").value=".*[A-Za-z0-9].*"
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")
Next

How To Retrieve Value from Webelement in QTP/UFT?
How To Retrieve Value from Webelement in QTP/UFT?
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.
How To Retrieve Value from Webelement in QTP/UFT?
How To Retrieve Value from Webelement in QTP/UFT?
Now you need to add these tables to your OR. atleast the last table..
Code:

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)
Next
Next
How To Retrieve Value from Webelement in QTP/UFT?
How To Retrieve Value from Webelement in QTP/UFT?

From the string you can find the policy number.

Hope this will help you.

Don't miss out!
Subscribe To Newsletter

Receive top technical news, lesson ideas, travel tips and more!

Invalid email address
Give it a try. You can unsubscribe at any time.

I am the founder and owner of the blog - TechTravelHub.com, always love to share knowledge on test automation,tools,techniques and tips.I am a passionate coder of Java and VBScript.I also publish articles on Travel ideas and great honeymoon destinations.Apart from these, I am a gear-head,love to drive across India. I have shared lots of articles here on How to travel several parts of India.Customization of cars aka car modification is my another hobby.Get in touch with me on [email protected]

5 Comments

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

  2. Vijunambiar Reply

    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.

    Thanks,
    Vijunambiar

  3. 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.

    Regards,
    Animesh

Write A Comment