How do I click on a web button that appears multiple times on a webpage?

馋奶兔 提交于 2019-12-12 06:23:24

问题


How do I click on a web button that appears multiple times on a webpage? How do I click all of them?

I am testing the "Like" button on a website (Webstagram.com) that is meant for you to view and operate your Instagram page from your desktop.

20 different pictures are displayed on a page and each picture has its own "like" button assigned to it. I can't identify it by "like" and in the outerhtml there are different values for each one. How do I write a script to identify each one?

Here is some of the info on the properties/values.

class: btn btn-default btn-xs likeButton

htmlid: N/a

htmltag: Button

innerhtml: <I class="fa fa-heart"></I>Like

outterhtml (Like button for pic #1): <BUTTON class="btn btn-default btn-xs likeButton" type=button data-target="1194558981914665301_8054519"><I class="fa fa-heart"></I>Like</BUTTON>

outerhtml (like button for pic#2)

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

NOTE I listed the outerhtml property values for two different pictures to show where the values differ. This is also the outerhtml code I tried to write to click on any like button and bypass any specific values:*

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

This is the script I tried to run that failed

1) systemutil.Run "websta.me/tag/graffiti"; 

2) Browser("#graffiti Instagram photos").Page("#graffiti Instagram photos").WebButton("<BUTTON class="btn btn-default btn-xs likeButton" type=button data-target=".*.*"><I class="fa fa-heart"></I>Like</BUTTON> ").Click 

3)wait(1) 

4) Browser("#graffiti Instagram photos").Page("#graffiti Instagram photos").WebButton("<BUTTON class="btn btn-default btn-xs likeButton" type=button data-target=".*.*"><I class="fa fa-heart"></I>Like</BUTTON> ").Click 

5) wait(1)

repeat... –


回答1:


Try something like this using Descriptive programming approach of QTP

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



回答2:


You can use VRI (visual relations identifier) to link an ambiguous object (your like button) to a well defined object (the picture).

This way you can say "click the like button that's closes to picture X".

Another way is to create a simple web-extensibility project that exposes a new object for the pictures which support the functionality of Liking a picture.



来源:https://stackoverflow.com/questions/35762562/how-do-i-click-on-a-web-button-that-appears-multiple-times-on-a-webpage

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!