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

365
Visualizações
Cypress: Accessing the last item in the list

I have a list in a simple html file only with emails received and I want to access the last email in the list from a specific email address. I tried with last (), but it didn't work, it just doesn't lead me to the last item, but to one of the first items in the list

cy.contains('test@test5.com').last().click() 

An item in the list has the following code:

<br>
<a href="/Emails/2020-12-03%2016_40_54%20-%20test@test5.com.html">2020-12-03 16_40_54 - test@test5.com.html</a>
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

It's a problem with Cypress, some commands "yield" many elements and some only one element.

You can check the the contains() - Yields section of the command, this one only gives you one element, which will be the .first() in the list.

.contains() yields the new DOM element it found.

IMO the docs should be more explicit. You learn to pick it up with experience, but can waste a lot of time trying to hack about with what looks like legit commands.

Try .get() and .filter(), using jQuery pseudo-selector :contains() which return all matching elements

cy.get('a')
  .filter(':contains(test@test5.com)')  
  .last()

or add the pseudo-selector :contains() inside the .get()

cy.get('a:contains(test@test5.com)')
  .last()
about 4 years ago · Juan Pablo Isaza Relatório

0

Assuming test@test5.com is unique and occurs once in your webpage, you write:

cy.contains('a', 'test@test5.com.html').click()
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