Reputation: 13
I am trying to get one of the element and trigger a click event. But since I have 4 of the element with same name I am trying to pin point it by this code.
cy.contains('*Real Estate Assets').parent().children().get('.formAddBtn.icon-btn.primary').click()
Even after pin pointing the section I am trying to click on, its still showing 4 other element that has same class name.
[Here is a image of dev console1
Upvotes: 1
Views: 2614
Reputation: 3721
Since the screenshot doesn't show the place where the buttons should be I can't completely be sure of this answer. But I did this assumption: Real Estate Assets, Assets and 2 more all have the button .formAddBtn.icon-btn.primary
. And you want to select the button for Real Estate Assets. If that assumption is correct this should work:
cy.contains('*Real Estate Assets')
.parent()
.find('.formAddBtn.icon-btn.primary')
.click()
By using find()
Cypress will search within the code yielded in the previous get()
. So it narrows the search down to everything below the parent of *Real Estate Assets.
Upvotes: 1