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

209
Views
How do you get the number of elements as an number in cypress?

Let's say I have three spans in a div.

<div>
  <span></span>
  <span></span>
  <span></span>
</div>

And let's say I have some janky code that counts the number of those spans and outputs the value somewhere else

<p>3</p>

In cypress I want to get the length of those spans and get the value that I've produced in my janky code and compare the two.

I've tried cy.get('div span').its('length'), but that yields the spans as an object...

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can do something like this. its('length') will return a number. <p>3</p> on invoking text gives a string, adding a + in front will convert it into a number +count.

cy.get('div span')
  .its('length')
  .then((len) => {
    cy.get('p')
      .invoke('text')
      .then((count) => {
        expect(len).to.equal(+count)
      })
  })
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!