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
Cómo obtener el nombre del elemento del botón en Cypress

Necesito crear una condición de que si en una página hay un botón con el valor de texto "Desbloquear", Cypress hará clic en él con anticipación. Puedo manejar la parte de hacer clic y la condición "si", necesito saber cómo obtener javascript para detectar qué botón tiene ese valor de texto "Desbloquear", ¡gracias!

 cy.get(".scroller").eq(1).find("button").then(($scroller) => { let test = $scroller //how to get the text value of the button? console.log(test) }) cy.wait(20000) cy.contains("Unblock").click() cy.wait(3000) cy.contains("Close").click() cy.contains("Back to main page").click()

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

0

1. Puede usar invocar('texto') para obtener el nombre del botón:

 cy.get('.scroller') .eq(1) .find('button') .invoke('text') .then((text) => { cy.log(text) //Logs button text })
  1. O también puede usar Jquery text() para obtener el nombre del botón:
 cy.get('.scroller') .eq(1) .find('button') .then(($scroller) => { cy.log($scroller.text()) //Logs button text })

Entonces, en su caso, puede aplicar el if-else de esta manera:

 cy.get('.scroller') .eq(1) .find('button') .then(($scroller) => { if ($scroller.text().trim() == 'Unblock') { //Do Something } else { //Do Something } })
about 4 years ago · Juan Pablo Isaza Report

0

Puede usar cy.contains() , ya que solo devuelve el botón con el texto requerido.

 cy.contains("button", "Unblock") .then(($scrollerButton) => { console.log($scrollerButton.text()) })
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!