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

113
Visualizações
Cypress: Optimize way to find the very deep element

I am trying to check the text inside a span element which is very deep down the dom tree, and I dont want to use a sequence of get/find command to find the text, here is my dom structure looks like:

<td>
  <div>
    <div>
      <div>
        <div></div>
         <div>
           <div>
             <div> </div>
             <span> **target** </span>
           </div>
         </div>
      </div>
     </div>
    <div>
     ...
    </div>
  </div>
</td>

thanks for the help

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You could get the first div element and find by span.

example:

const spanEl = cy.get('div').find('span')

If the parent div element has a CSS class or some unique attribute, it would be easier.

const spanEl = cy.get('#attribute-of-div-el').find('span')

ref: https://docs.cypress.io/api/commands/get#Get-vs-Find

about 4 years ago · Juan Pablo Isaza Relatório

0

If your <span> has unique text then you'll benefit from using cy.contains(). It is quite powerful and underused.

cy.contains('span', 'Your unique text')

you can even use regex

cy.contains('span', /your unique text/)
about 4 years ago · Juan Pablo Isaza 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