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,
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 textSi 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') })