QTP-获取元素的值

发布于 2024-08-19 03:31:02 字数 148 浏览 2 评论 0原文

我从 QTP 开始,只是不知道如何获取元素的值。例如,当我只想比较谷歌找到的结果数量时。我尝试使用对象间谍选择元素并使用 Val(Element) 将值分配给变量..但它不起作用。有人可以帮忙解决这个问题吗?顺便说一句,我不确定选择与对象间谍进行比较的文本(元素)是否正确。 谢谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

君勿笑 2024-08-26 03:31:02

您应该使用 GetROProperty 来获取文本,然后解析它以获取值。

查看 Google 结果页面,我发现结果位于第三个粗体标记中带有 id=resultStats 的段落中。

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

因此,以下脚本获取数字(作为带逗号的字符串)。

Browser("micclass:=Browser")
 .Page("micclass:=Page")
  .WebElement("html id:=resultStats")
   .WebElement("html tag:=b","index:=2").GetROProperty("innertext")

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")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文