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

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

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