Created
March 19, 2024 16:25
-
-
Save SarahElson/9dadb665f7834e904120d9bd46f571f8 to your computer and use it in GitHub Desktop.
How To Check If An Element Exists In Cypress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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