Skip to content

Instantly share code, notes, and snippets.

@SarahElson
Created March 19, 2024 16:25
Show Gist options
  • Select an option

  • Save SarahElson/9dadb665f7834e904120d9bd46f571f8 to your computer and use it in GitHub Desktop.

Select an option

Save SarahElson/9dadb665f7834e904120d9bd46f571f8 to your computer and use it in GitHub Desktop.
How To Check If An Element Exists In Cypress
export default class MainPage {
static elExists(text){
cy.get('body')
.then($body => {
if ($body.find(text).length) {
return 'text'
}
return '.both.text-reset'
})
.then(selector => {
cy.get(selector)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment