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

159
Vistas
Cypress/VueJS Selecting Element that is dynamically added after another action

I'm testing a feature where a button appears for the user to click AFTER they have taken another action.

Before taking the action I'm checking if the button exists:

cy.get('span')
    .contains('Select')
    .parent('button')
    .should('not.exist');

And after the action I'm trying to find that same button like this but it fails. Would anyone know how to do this in Cypress?

Here is my entire code:

cy.get('span')
    .contains('Select')
    .parent('button')
    .should('exist');
/* eslint-disable */

describe('Workgroup Switch', () => {
    beforeEach(() => {
        cy.visit('/login');
        cy.get('input[id="username"]').type('boss@example.com');
        cy.get('input[id="password"]').type('password');
        cy.get('button[id="login-button"]').click();
        cy.url().should('include', '/offers/workgroup');
    });

    it('switch workgroup', () => {
        cy.get('span')
            .contains('Select')
            .parent('button')
            .should('not.exist');

        cy.get('.v-overlay__scrim').click();

        cy.get('.text-h6')
            .contains('Workgroup #1')
            .parent()
            .parent()
            .click();

        cy.contains('Make this my default workgroup');

        cy.get('span')
            .contains('Select')
            .parent('button')
            .should('exist');
    });
});
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You should use the combined form of contains() to get the correct element.

cy.contains('span', 'Select')
  .parent('button')
  .should('exist');

Doing it in two parts like this

cy.get('span')
  .contains('Select')

Cypress finds the first span on the page and then repeatedly checks it's text for "Select", but it does not repeat the cy.get('span') part.

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