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

211
Visualizações
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 Respostas
Responde à pergunta

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 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