Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

207
Visualizações
Why display none for cypress is still visible?

I am testing my website using cypress, but there's one thing that confused me, is that when I using :

display:none 

And I use this line to test if the div still exist in the page:

cy.get('[data-cy=searchBar]').should('not.exist')

It will still be detected as visible when testing, I think the reason is that I can still see the element inside the chrome dev tool, but I can't see it on the web page.

I know that I can simply use CSS attribute to check the display to finish my test, but I am wondering how this visible in cypress is designed, and why in this case it doesn't work?

enter image description here

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

exist and visible are two different assertions. Exist checks whether the element is present in the DOM. Visible checks whether the element is visible on the DOM.

Now for your element where it has a property of display: none, this signifies that element is not visible but it does exists.

cy.get('[data-cy=searchBar]').should('be.visible') //Fails
cy.get('[data-cy=searchBar]').should('exist') //Passes
about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda