I have a problem with reloading elements. On our site there are 10 elements on each pagination page. If you delete an element the next element slides in and so on. The problem I have is that initially the 10 elements are found. If I delete now all 10 elements my function is finished although further elements were reloaded which must also be deleted. How can I catch the reloaded elements in the function as well?
deleteDeliveryAddresses() {
const deleteRow = (selector, rowsToDelete) => {
if (rowsToDelete === 0) return
cy.get('foerch-delivery-addresses-item .row:contains("automated address name")').eq(0)
.as('rowDeleted')
.find('button:nth-child(2)').click({force:true})
cy.xpath("//button[normalize-space()='Bestätigen']").should('be.visible').click()
cy.xpath("//button[normalize-space()='Bestätigen']").should('not.exist')
cy.wait(1000)
deleteRow(selector, --rowsToDelete)
}
const selector = 'foerch-delivery-addresses-item .row:contains("automated address name")'
cy.get(selector).then($rows => {
const rowsToDelete = $rows.length
deleteRow(selector, rowsToDelete)
})
}