trickspring
trickspring

Reputation: 3

How to find xpath for a label inside a button tag

I have a HTML like below:

<button id = "btn-89sd788" ng-click="ctrl.seeDetail()" aria-label = "go to item 1222" class="btn btn-green ng-binding" xpath="1"> 
"view details"
</button>

the form has multiple buttons with similar html code, the button id is different but the aria-label text is same with the item number(in this case 1222) ibeing incremental. I want to loop clicking on the buttons based on the aria label. How do I find the xpath for this button.

Upvotes: 0

Views: 1134

Answers (2)

zx485
zx485

Reputation: 29042

Try this XPath-1.0 expression to choose the <button>s incrementally:

//button[contains(@aria-label,'go to item')]

This expression selects all <button>s that satisfy the condition.

Upvotes: 1

Peter
Peter

Reputation: 898

Is this what you're looking for?

//button[@aria-label="go to item 1222"]

This will find all buttons with the tag aria-label equal to "go to item 1222"

In order to iterate through them, you could do something like: (Python)

for i in range(num_buttons):
  xpath = '//button[@aria-label="go to item "' + i + ']'

Upvotes: 1

Related Questions