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

762
Views
Cypress: ¿Cómo saber si el elemento es visible o no al usar la condición If y xpath?

Cypress: ¿Cómo saber si el elemento es visible o no al usar la condición If?

La respuesta de la pregunta anterior funciona perfectamente para los selectores de CSS. La respuesta es

 cy.get("body").then($body => { if ($body.find("selector_for_your_button").length > 0) { //evaluates as true if button exists at all cy.get("selector_for_your_button']").then($header => { if ($header.is(':visible')){ //you get here only if button EXISTS and is VISIBLE } else { //you get here only if button EXISTS but is INVISIBLE } }); } else { //you get here if the button DOESN'T EXIST assert.isOk('everything','everything is OK'); } });

Quiero lograr algo similar pero para XPath. ¿Alguien puede ayudarme?

Gracias de antemano

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

0

Con XPath puedes usar count()

 cy.xpath(`count(//*[@class="${selector}"])`) .then(count => { if (count > 0) { cy.xpath(`//*[@class="${selector}"]`) // repeat without count .click() } else { } })

Pero creo que la advertencia de @jjhelguero sigue vigente. No hay ningún reintento con las pruebas condicionales, por lo que está perdiendo la mayor ventaja de Cypress: reducir la descamación en sus pruebas.

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!