so I'm back with the question again:) I previously asked similar one but this one a bit tricky for me. so I want to make a specific card visible after clicking on next button in the carousel and stop clicking after that specific card becomes visible, here is the code I have but when executed it shows that that specific card is visible but it won't stop clicking next button. Probably my mistake is chilling but I'm learning and will get better:) thank you guys !
cy.get('.carouselCards').find('.1stCard').each(($el, index, $list) => {
const cardText = $el.find('.cardTitle').text()
if(cardText.includes('specific name of the card I'm looking for')) {
cy.wrap($el).should('be.visible')
} else { cy.get ('.carouselButton').click()
}
})
You can break the loop in Cypress by returning false. Please try below
cy.get('.carouselCards').find('.1stCard').each(($el, index, $list) => {
const cardText = $el.find('.cardTitle').text()
if(cardText.includes('specific name of the card I'm looking for')) {
cy.wrap($el).should('be.visible');
return false;
} else {
cy.get ('.carouselButton').click();
}
})