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

109
Vistas
Select one of two different classes within Element with Cypress

In our application we use tasks for the user to go through a certain flow of work. This task can have two different classes, depends on which task the user has in front of him.

The class 'task__options' and 'ap-option' are within the 'task__inner' class.

I have to following code, but it never goes through the IF only the ELSE. Do you have any suggestions to solve this?

Then('I click the task option {string}', (task: string) => {

    cy.get('.task__inner').within(($ele) => {
        if($ele.hasClass('task__options')){
            cy.get('.task__options').click();
        } else {
            cy.get('.ap-option').click();
        }
    });
});
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You can write the two classes separated by , so if either one of it present, then it will perform the click().

cy.get('.task__options,.ap-option').click()

Then your code will look like:

cy.get('.task__inner').within(() => {
  cy.get('.task__options,.ap-option').click()
})
about 4 years ago · Juan Pablo Isaza Denunciar

0

Thanks to @Alapan I have a solution for this issue, but I also had include a API Call that would go off if one of the two classes was present.

Then('I click the task option {string}', (task: string) => {
    let clickButton = task => {
        cy.get('.task__options,.ap-option').contains(task, {matchCase: false, timeout: 30000})
            .scrollIntoView()
            .click();
    };
    cy.get('.task__inner').within(() => {
        cy.get('.task__form').then(($ele) =>{
            if($ele.hasClass('task__options')){
                cy.intercept("POST", "/bla-bla/api/Task/ResolveConditionalWait/**").as('ResolveConditional')
                clickButton(task);
                cy.wait('@ResolveConditional')
            } else {
                clickButton(task);
            }
        })
    });
});
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