如何点击网页上多次出现的网页按钮?

时间:2016-03-03 03:19:30

标签: automation qtp

如何点击网页上多次出现的网页按钮?如何点击所有这些?

我正在测试网站(Webstagram.com)上的“赞”按钮,该按钮用于从桌面查看和操作您的Instagram页面。

页面上显示20张不同的图片,每张图片都有自己的“喜欢”按钮。我不能通过“喜欢”识别它,而在outerhtml中,每个都有不同的值。如何编写脚本来识别每个脚本?

以下是有关属性/值的一些信息。

上课message.as_json => {"id"=>1, "body"=>"Etsy actually four dollar toast seitan. Schlitz twee kale chips pork belly franzen tote bag.", "flagged"=>true, "created_at"=>Wed, 02 Mar 2016 21:33:55 UTC +00:00, "updated_at"=>Wed, 02 Mar 2016 21:33:55 UTC +00:00}

htmlid :不适用

htmltag :按钮

innerhtml: btn btn-default btn-xs likeButton

outterhtml(与图片#1的按钮相似): <I class="fa fa-heart"></I>Like

outerhtml(如图2的按钮)

<BUTTON class="btn btn-default btn-xs likeButton" type=button data-target="1194558981914665301_8054519"><I class="fa fa-heart"></I>Like</BUTTON>

注意我列出了两张不同图片的outerhtml属性值,以显示值的不同之处。这也是我试图编写的外部HTML代码,点击任何类似按钮并绕过任何特定值:*

outerhtml:<BUTTON class="btn btn-default btn-xs likeButton" type=button data-target="1194558967727891183_339837919"><I class="fa fa-heart"></I>Like</BUTTON>

这是我试图运行失败的脚本

<BUTTON class="btn btn-default btn-xs likeButton" type=button data-target=".*_.*"><I class="fa fa-heart"></I>Like</BUTTON>

重复... -

2 个答案:

答案 0 :(得分:1)

使用QTP的Descriptive programming方法尝试这样的事情

Set oDesc = Description.Create
oDesc("micclass").value = "WebButton"
oDesc("html tag").value = "BUTTON"
oDesc("class").value = ".*likeButton"
odesc("class").RegularExpression = True

'Find all the Links
Set obj = Browser().Page().ChildObjects(oDesc)

Msgbox obj.Count  'will show how many buttons are found
For i = 0 to obj.Count - 1              
   Obj(i).Click
   Wait 2  'waits for 2 sec
Next

答案 1 :(得分:0)

您可以使用VRI (visual relations identifier)将不明确的对象(您的喜欢按钮)链接到定义良好的对象(图片)。

通过这种方式,您可以说“点击关闭图片X 按钮。”

另一种方法是创建一个简单的web-extensibility项目,该项目为支持 Liking 图片功能的图片公开新对象。