In material UI table, there is one record which can exist or not. The Scenario is, if that row is present (based on ‘Name’ column) then delete otherwise go to Else block and write, that record is NOT present.
In my code, if row present then it’s executed ‘IF’ block and rest is fine But when row doesn’t present then it is not going in ‘ELSE’ block like row doesn’t exist.
cy.get('.MuiTable-root').first().contains(Program1).then(($el) => {
if ($el.length > 0) {
// Element exists, do something
cy.log(Program1 + ': Program found.')
cy.get('.MuiTable-root').first().contains('tr', Program1).find('td').first().find('svg.MuiSvgIcon-root').eq(2).click();
cy.wait(10000)
cy.get('[title="Save"]').click()
cy.wait(10000)
cy.log( Program1 + ': Program deleted.')
} else {
// Element does not exist, do something else
console.log(Program1 + ': Program not found.');
cy.wait(3000)
cy.log( Program1 + ': Program not found.')
}
cy.wait(5000)
cy.get('.lw-header__logout > img').click();
cy.wait(5000)
})
Getting Error when executing the code (row doesn’t exist)
Thank you in advance for help, as I am stuck in this case.