I have function in another class file (following pageObject):
getElementExists(xpathSelector){
cy.xpath(`count(${xpathSelector})`).then(count => {
const exist = (count > 0) ? true : false
console.log(exist)
return cy.wrap(exist)
})
}
In another js, I try to use function:
basePage.getElementExists(XPath).then((fi) => {
console.log(fi)
})
I get TypeError: Cannot read properties of undefined (reading 'then')
How can I return boolean in Cypress and use it further?
The xpath library is no longer used, but you can still evaluate
xpathSelectorwith document.evaluate which is built into the browser.An example test: