Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

255
Views
Cypress obtener elemento dentro de cada

tengo este codigo

 cy.visit('http://localhost:3000/') cy.get('.list').each((list, index, lists) => { cy.contains('Learn').click() cy.url().should('include', '/localhost') cy.get(`[data-testid="card-input-${index}"]`) .type('Learn Cypress') .should('have.value', 'Learn Cypress') cy.get(`[data-testid="btnAdd-${index}"]`).click() cy.get(".card").each((card, index, cards) => { cy.get(cards).should('have.length', 4) }) })

Necesito esta línea para devolver solo tarjetas de la lista específica. Ahora mismo devuelve todas las cartas de todas las listas.

 cy.get(cards).should('have.length', 4)

Intenté jugar con literales, pero devolvió [objeto objeto]

 cy.get(`${cards}>card`).should('have.length', 4)
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Entonces, el primero each está recorriendo la lista y asumo que dentro de la lista desea acceder a las tarjetas, entonces puede hacer algo como esto:

 cy.visit('http://localhost:3000/') cy.get('.list').each((list, index, lists) => { cy.contains('Learn').click() cy.url().should('include', '/localhost') cy.get(`[data-testid="card-input-${index}"]`) .type('Learn Cypress') .should('have.value', 'Learn Cypress') cy.get(`[data-testid="btnAdd-${index}"]`).click() cy.wrap(list).within(() => { cy.get('.card').should('have.length', 4) //or cy.get('.card').its('length').should('eq', 4) //or cy.get('.card') .its('length') .then((len) => { cy.get('.card').should('have.length', len) }) }) })
about 4 years ago · Juan Pablo Isaza Report

0

La razón por la que ha estado obteniendo todas las tarjetas de todas las listas se debe a la búsqueda de cy.get() desde el elemento DOM raíz. Para limitar su búsqueda a un elemento DOM anterior, querrá usar .within() o .find() .

 cy.visit('http://localhost:3000/') cy.get('.list').each((list, index) => { cy.contains('Learn').click() cy.url().should('include', '/localhost') cy.get(`[data-testid="card-input-${index}"]`) .type('Learn Cypress') .should('have.value', 'Learn Cypress') cy.get(`[data-testid="btnAdd-${index}"]`).click() cy.wrap(list) .find('.card') .should('have.length', 4) })
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!