Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

209
Vistas
Validate button click until disabled using Cypress

I am trying to validate a button click using Cypress. I should be able to click on a button when there are slides available. If there are no slides the button should not be clickable and gets disabled by adding a disabled class to the button. Can anyone please suggest a better solution to validate this scenario?

Below is the HTML code when next slide is available:

<button class="arrow"><span class="screen-reader-only">Previous slide</span></button>

HTML code when next slide is not available and disabled class gets added:

<button class="arrow disabled"><span class="screen-reader-only">Previous slide</span></button>

Cypress code that I am trying to validate:

it('Validate the button is clickable',()=> {
        cy.get('.arrow')
          .then(($btn) => {
              if($btn.is(":disabled")){
                  $btn.should('have.class','disabled')
                      .and('have.css','background-color','rgb(62, 64, 69)') 
                      cy.log('Arrow is disabled and not clickable')
              } else {
                  cy.wrap($btn).click()
                  expect($btn).to.have.css('background-color','rgb(172, 42, 0)')
              }
          })
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can also use .hasClass('disabled') as there is a class disabled added. Also since there would multiple arrow buttons use an each instead of a then.

it('Validate the button is clickable', () => {
  cy.get('.arrow')
    .should('be.visible')
    .each(($btn) => {
      if ($btn.hasClass('disabled')) {
        cy.wrap($btn)
          .should('have.class', 'disabled')
          .and('have.css', 'background-color', 'rgb(62, 64, 69)')
        cy.log('Arrow is disabled and not clickable')
      } else {
        expect($btn).to.have.css('background-color', 'rgb(172, 42, 0)')
        cy.wrap($btn).click()
      }
    })
})
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda