Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

111
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!