1

I'm trying to click on this specific edit button. I'm using find method in ruby to do so, the problem I'm running into is that It's not able to find the specific element.

<i ng-click="grid.appScope.editMOO(row.entity._id)" class="ca ca-pencil-square-o" role="button" tabindex="0"></I>

Here is my code trying to click on the edit button.

find('.ng-click', class: 'ca ca-pencil-square-o').click
Rubyman543
  • 165
  • 5
  • '.ng-click' will look for elements with the class `ng-click`. Its actually an attribute in your code. You could fix it by adding a class to the buttons that you target. But I would add an actual text to the button for screen readers that you can use to target in Capybara. https://accessible360.com/accessible360-blog/use-aria-label-screen-reader-text/ – max Apr 12 '22 at 16:09

2 Answers2

0

To click on the desired button you can use either of the following Locator Strategies:

find('i[ng-click^="grid.appScope.editM"]').click

or

find('i[ng-click^=grid.appScope.editM]').click
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

Depending on the ng-click attribute for this is not a great idea, instead do either of

find('i[role="button"]', class: 'ca-pencil-square-o').click

or

find('i[role="button"].ca-pencil-square-o').click

Note, if you wanted to test for both classes like you were doing originally you pass an array to the class option

find('i[role="button"]', class: ['ca', 'ca-pencil-square-o']).click

but that doesn't really make sense to check for both 'ca' and 'ca-pencil-square-o'

Thomas Walpole
  • 48,548
  • 5
  • 64
  • 78