I want to execute some function only when certain element is present using its data-test id.
Below is what I am trying to do:
cy.getByTestId('checkbox-id').then((el) => {
if (el) {
cy.tableSelectAll();
}
}
Here I am expecting it to execute tableSelectAll() only if there is an element. But this fails saying it couldn't find an element with id "checkbox-id".
How can I fix this? Could someone please help me with this?