Search code examples
hp-uft

How to retrieve the number from the field in UFT?


Can you please provide a script where I can get the value "3" and store in a field? Validating number of sales, this number changes every time.

Here is the Obj Rep

"Class Name:=WebElement",
"abs_x:=24",
"abs_y:=177",
"acc_name:=",
"class:=indicator",
"height:=67",
"html id:=",
"html tag:=DIV",
"innerhtml:=3",
"innertext:=3",
"outerhtml:=<div class=""indicator"" _ngcontent-c7="""">3</div>",
"outertext:=3",
"role:=",
"title:=",
"type:=",
"visible:=True",
"width:=54",
"x:=24",
"xpath:=//DIV\[@id=""number of sales""\]/DIV\[1\]/DIV\[1\]/DIV\[1\]/DIV\[1\]",
"y:=177"

Solution

  • First you have to remove the innertext and innerhtml form the OR object properties. Then use GetROProperty to retrieve the value from the application.

    Browser().Page().WebElement().GetROProperty("innertext")
    

    Btw if you are mentioning all the properties that mentioned in the question as part OR Object Identification strategy, you have to seriously consider updating it. I think you can remove everything except the class or xpath, that will identify the element uniquely.

    And if you don't remove the innertext and innerhtml from the OR Object identification properties then your test will fail if the number 3 changes in future. If you still want to maintain all the properties then you just have to check the .exists on the element to validate the text =3 as the webelement itself have innertext:3