Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

210
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda