Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

160
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda