Is there a straightforward way to determine if an element is present, and then proceed with specific steps based on its presence or absence?
I attempted the following approach, but it did not yield the desired results:
Cypress.Commands.add('deleteSomethingFunction', () => {
cy.get('body').then($body => {
if ($body.find(selectors.ruleCard).length) {
let count = 0;
cy.get(selectors.ruleCard)
.each(() => count++)
.then(() => {
while (count-- > 0) {
cy.get('body')
// ...
// ...
}
});
}
});
});
I am seeking a simple solution that can be easily incorporated using basic JavaScript syntax like an if-else block or the then() section of a Promise.
Something akin to the following implementations from the Webdriver protocol:
driver.findElements(By.yourLocator).size() > 0
- Check for element presence during a wait operation
Your advice would be greatly appreciated. Thank you.