Rahul Gupta
Rahul Gupta

Reputation: 69

How to check if the element with visibility exists or not cypress

Is there any way to check if the element with visibility exists or not

cy.get("[data-ta='member_account_switch']:visible")

event though there are two elements with same data key exists on the dom but both are not visible I just want to check if the visible element exists or not

cy.get("[data-ta='member_account_switch']:visible").should('not.exists')

this above statement does not work as cy.get("[data-ta='member_account_switch']:visible") is trying to find the element. and I get the below error

Timed out retrying: Expected to find element: [data-ta='member_account_switch']:visible, but never found it.

can someone help here? Thanks

Upvotes: 1

Views: 2508

Answers (1)

Srinu Kodi
Srinu Kodi

Reputation: 512

You are doing it wrong in both the cases. You should write like below. cy.get() method takes only locators. In your case the locator is [data-ta='member_account_switch'] and on top of that you have to check it's property.

cy.get("[data-ta='member_account_switch']").should('be.visible')

Please read about Cypress and how to use these before posting simple things here.

Upvotes: 1

Related Questions