Ruby capybara autotests. It is not possible to click on certain button due that they all have same css

Viewed 16

Page has multiple buttons. I need to click first one, but they all have same class one-employee__remove-btn

I could try xpath, but this kinda looks scary /div[contains(@class,'one-employee__user')]/div/div/p[contains(.,'#{email}')]//div[contains(@class,'one-employee__user')]/div/div/p[contains(.,'terry@lind.co')]/../../../div[contains(@class, 'one-employee__remove-btn-cont')]/button

is there a possibility to make it happen using css? full html for element <button data-v-6454fca6="" title="Fjern" class="one-employee__remove-btn"></button>

enter image description here

2 Answers

If you're sure that it's always the first button you want to click, and assuming no other buttons on that page have the one-employee__remove-btn class you can try something like

all(".one-employee__remove-btn").first.click

Capybara supports first(".one-employee__remove-btn").click

Related