Created
March 19, 2024 16:24
-
-
Save SarahElson/305ad0dcee8148d1af2956feeccf7e77 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
import config from './config.json' | |
import MainPage from '../../page-objects/components/MainPage' | |
describe('Elements Exist', () => { | |
it('Elements exist across the pages', () =>{ | |
cy.visit(`${config.URL3}`) | |
//Element Exists | |
cy.get('body') | |
.then($body => { | |
if ($body.find('.compare-total').length) { | |
return '.compare-total' | |
} | |
return '.both.text-reset' | |
}) | |
.then(selector => { | |
cy.get(selector) | |
}) | |
//Improve Element Exist Method | |
MainPage.elExists('.content-products.entry-content.flex-grow-0.order-5.order-md-4 > div > div:nth-of-type(1)') | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment