Issue
im new to test e2e and im trying to click on a specific button, i gave it a data-cy that automatically is been attributed to other buttons created dinamycally.
How can i click on first button? The code i use for click on a single data-cy is this:
When('I click on button data-cy:{string}', (element) => {
cy.get('[data-cy="' + element + '"]').click();
});
Thanks for attention
EDIT
Already tried to add .first() on line, but i would like to use a method that allowed me to use the selector also for only the second/third... button. Btw for the specific test the .first() syntax works perfectly
Solution
You can use eq(0)
for this.
cy.get('[data-cy="' + element + '"]').eq(0).click()
Answered By - Alapan Das
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.