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

278
Visualizações
How to get all the links of all children of an element

I have a element that I am able to locate:

cy.get('[foo="bar"]')

Now I'm trying to locate all the a elements within said element:

cy.get('[foo="bar"] a') this should give me all the elements that have the parent (or grandparent foo, and is <a>.

However, this only seems to select one element (that is parent foo and a), not all the elements, since I'm only getting one href saved.

This is what I use to save the results:

cy.get('[foo="bar"]').invoke('attr', 'href')
            .then((hrefs) => {
            cy.writeFile('./cypress/downloads/results.txt', hrefs)
        });     

How do I select all the children, that are <a>, of [foo="bar"] and then how do I extract all of their href attributes?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I think the step .invoke('attr', 'href') is just returning the first, see .attr()

Get the value of an attribute for the first element in the set of matched elements

So, maybe

cy.get('[foo="bar"] a')
  .then($els => {
    const hrefs = [...$els].map(el => el.getAttribute('href'))
    cy.writeFile('./cypress/downloads/results.txt', hrefs)
  })
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