I am trying to select two buttons one after one , a Delete button and after that the Yes popup confirmation ,by this:
cy.get('.btn-danger').last().click();
cy.get('.btn-primary').click();
But i got this error:
CypressError: cy.click() can only be called on a single element.
Your subject contained 2 elements.
Pass { multiple: true } if you want to serially click each element.
Double click all buttons found on the page By default, Cypress will iteratively apply the double click to each element and will also log to the Command Log multiple times. You can turn this off by passing multiple: false to . dblclick() .
Click all elements with id starting with 'btn' By default, Cypress will error if you're trying to click multiple elements. By passing { multiple: true } Cypress will iteratively apply the click to each element and will also log to the Command Log multiple times.
I think there are two buttons with btn-primary
class in your popup DOM (yes and cancel?). Try to access the yes confirmation button by its id or something. Or if you're sure about the order, then use .first()
or .last()
like you used for clicking the delete button.
Another method is with .eq(index)
assuming you have array of two buttons [0, 1]
and last being 1
cy.get('.btn-danger').eq(0).click();
cy.get('.btn-primary').eq(1).click();
Check for documentation Eq function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With