Hi, I am beginning with QTP and just cannot find out how to get value of element. For example when I just want to compare the number of results found by google. I tried to select the element with object spy and use Val(Element) to assign the value into variable..but it doesnt work. Could anyone help with this? BTW, I am not sure whether selecting the text (element) to compare with Object spy is correct. Thanks!
+1
A:
You should use GetROProperty
in order to get the text and then parse it for the value.
Looking at a Google results page I see that the result is in a paragraph with id=resultStats
in the 3rd bold tag.
<p id="resultStats"> Results <b>1</b> - <b>10</b> of about
<b>2,920,000</b>
for <b>qtp</b>. (<b>0.22</b> seconds)</p>
So the following script gets the number (as a string with commas).
Browser("micclass:=Browser")
.Page("micclass:=Page")
.WebElement("html id:=resultStats")
.WebElement("html tag:=b","index:=2").GetROProperty("innertext")
Motti
2010-01-24 10:16:56
Thank you, is there any way how to find out the element ID from QTP instead of reading the source? ObjectSpy shows only "Webelement"
Tomas
2010-01-24 11:01:43
@Tomas, yes it should appear as `html id` in the object spy
Motti
2010-01-24 17:04:40