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

264
Views
Javascript: Cypress: seleccione una muestra que no contenga valor

Quiero seleccionar un valor aleatorio de un menú desplegable, con la restricción de que no se debe seleccionar un valor específico.

 const initialOrderReason = cy.xpath("//tbody/tr[1]/td[4]"); tkm .dropdownOptions() .should("be.visible") .then((options) => { cy.get(Cypress._.sample(options)) .not.contain(initialOrderReason) });

¿como es posible?

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

0

Hay mucho código relevante que no ha mostrado, incluido el HTML, pero aquí está mi solución basada en lo que ha proporcionado

Se debe acceder a cy.xpath("//tbody/tr[1]/td[4]") a través .then() en lugar del valor devuelto.

Y para todos los elementos extraer el texto de los elementos.

 cy.xpath('//tbody/tr[1]/td[4]') .invoke('text') // extract text .then(initial => { tkm.dropdownOptions().should("be.visible") .then((options) => { const texts = [...options].map(option => option.innerText) // extract texts const notInitial = texts.filter(text => text !== initial) // filter out initial const random = Cypress._.sample(notInitial) // random other value // Assuming "//tbody/tr[1]/td[4]" gives a <select> element cy.xpath('//tbody/tr[1]/td[4]').select(random) }); cy.xpath('//tbody/tr[1]/td[4]') // requery the dropdown .should("not.have.text", initial); // to allow DOM to change })
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!