I am trying to use cypress-if for validating whether the element is present or not using XPath. In some cases, it is hard to write CSS selectors as compared to XPath. Upon trying the same with XPath, we are getting 'element not found error' when it is not present, but it is working fine when it is present. Since the test case trying to achieve when the element is not found I need to update something else. Below is my sample code.
cy.xpath(objects[page][locator]).if('exist').then(()=>{
cy.log('locator Exists')
}).else().then(()=>{
cy.log('Locator Not Exists')
})
I am trying to use cypress-if for validating whether the element is present or not using XPath. In some cases, it is hard to write CSS selectors as compared to XPath. Upon trying the same with XPath, we are getting 'element not found error' when it is not present, but it is working fine when it is present. Since the test case trying to achieve when the element is not found I need to update something else. Below is my sample code.