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

242
Views
Cypress: compruebe si existe la opción Seleccionar

Estoy tratando de verificar si hay una opción en mi selección usando el código a continuación, pero sigue fallando, ¿alguien puede ayudarme?

My Select tiene alrededor de 70 nombres y estoy tratando de hacer un bucle de todos ellos buscando el nombre específico.

 cy.get('[id="names"] option').each(($ele) => { expect($ele).to.have.text('Have This Name') })

Gracias por adelantado,

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

0

No usaría .each() , solo uno pasará pero cualquier otro fallará.

Use .contains() si su texto es lo suficientemente específico (no en múltiples opciones)

 cy.contains('[id="names"] option', 'Have This Name') // fails only if // no option has the text

Si tiene que coincidir exactamente, filtre las opciones

 cy.get('[id="names"] option') .filter((idx, el) => el.innerText === 'Have This Name') // fails if filter // returns 0 items

Si quieres .each() por otra razón, esto servirá

 let found; cy.get('[id="names"] option') .each(($option) => { if ($option.text() === 'Have This Name') { found = $option return false // return now, have found it } }) .then(() => { // after loop exit expect(found).to.have.text('Have This Name') })
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!