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

236
Views
¿Cómo invocar todos los valores de opción de seleccionar con cypress/javascript?

Estoy tratando de obtener todos los values en select tag para tener una matriz. Este es mi código:

 cy.get('[data-tab-name-prefix="selectedFonds[0]]') .scrollIntoView() .should('be.visible') .find('[name="selectedFonds[0][name]"]') .find('option') .invoke('attr', 'value').then($options => { cy.log($options) }) 

 <div data-tab-name-prefix="selectedFonds[0]"> <div class= something> <div class= something else> <select class=form-control name="selectedFonds[0][name]"> <option value="first value"> First Value </option> <option value="second value"> Second Value </option> <option value="third value"> Third Value </option> <option value="forth value"> Forth Value </option> </select> </div> </div> </div>

El problema es que solo devuelve la primera opción... no todas.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Mi sugerencia sería apuntar al elemento con el atributo de datos y luego hacerlo within() . Luego apunte al elemento de selección y haga children() . Seguido de un bloque each() para iterar sobre cada elemento de opción.

 const values = ['first value', 'second value', 'third value', 'fourth value'] cy.get('[data-tab-name-prefix="selectedFonds[0]]') .scrollIntoView() .should('be.visible') .within( ($el) => { cy.get('select')//based on your HTML you have only one select inside this div .should('be.visible') .children() .each( ($el, index) => { cy.get($el) .should('have.value', values[index]) }) })
about 4 years ago · Juan Pablo Isaza Report

0

.invoke('attr', 'value') está causando el problema, cambia la matriz a un solo valor.

Mueva la llamada attr() dentro de .then() .

 const expectedValues = ['First value', 'Second value', 'Third value', 'Fourth value'] cy.get('[data-tab-name-prefix="selectedFonds[0]]') .scrollIntoView() .should('be.visible') .find('[name="selectedFonds[0][name]"]') .find('option') .then($options => { const values = [...$options].map(option => option.getAttribute('value').trim()) return values }) .should('deep.eq', expectedValues) })
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!