Search text only in a HTML class

Hello
I just realize I can do click on a determined ‘buttonZ’ using this:

command: click
target: //*[text()[contains(.,‘buttonZ’)]]

But I would like to click only inside on the html class=“xxx” and get the number of times clicked. For instance, here the result must be 4:

  <div class="xxx">
  <button>buttonZ</button>
  <button>fads</button>
  <button>buttonZ</button>
  <button>buttonZ</button>
  <button>afds<button>
  <button>buttonZ</button>
  </div>

  <div class="abc">
  <button>buttonZ</button>
  <button>buttonZ</button>
  <button>buttonZ</button>
  <button>tatata<button>
  <button>tetete</button>
  <button>buttonZ</button>
  <button>buttonZ</button>
  </div>

…this is an XPath question, or?

Maybe this helps: php - how to click a button under a nested div using xpath and class in behat3 - Stack Overflow

You mean you want to search for the number of “buttonZ” instances within class=“xxx”?

Hello
Search, click and get the number of times clicked, ( “buttonZ” instances only inside on the html class=“xxx” )

I guess you can use a flow control command such as “While” or “Do”:

https://ui.vision/rpa/docs/selenium-ide/do-repeatif

Then use a variable to keep track on the number of times clicked.

Hello. Yes! But, inside the flow control sentence, how can I define the function to only click on the “buttonZ” buttons from the html class=“xxx” ?

If I understand correctly, you want to click a button with class=“xxx”. If so, you can explore using xpath, something similar to:

//button[@class=‘xxx’]

You can choose the Nth element by using:

(//button[@class=‘xxx’])[N]