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

162
Views
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 answers
Answer question

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 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!