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

261
Views
How to test multiple floating messages with the same content in cypress?

I am fairly new to cypress and practicing its functionalities on Facebook app. I am having an issue on testing these following scenarios:

1.When clicked on First Name, this floating dialog should be visible. 2.Validating the text in the dialog box to be 'What's your name?'. 3.When clicked on Last Name, again a floating box with the same content "What's your name?" should be visible.

Now I am able to test the first two scenario with this.

cy.get('[name="firstname"]').click();//i)-> Click on the firstname
        cy.get('[name="lastname"]').click();//ii)-> Click on the last name    
        cy.get('[name="firstname"]').click(); //iii)-> This will triggers the error message popup for firstname 
        cy.contains('What\'s your name?').should('be.visible').and('contain','What\'s your name?');// Checking the message popup should be displayed and its message is 'What's your name'
        cy.get('[name="lastname"]').click();//v)-> This will trigger the error message popup for lastname
    
        cy.contains('What\'s your name?').should('be.visible').and('contain','What\'s your name?');//vi)-> Checking for that message but not working

But in the third scenario, it is showing the error. I tried to access the element using id but it was showing not found. Error Message Facebook Page

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I think cy.contains('What\'s your name?') is catching the message from firstName field which was activated from the initial two commmands but hidden when you navigated to the lastName field (but still remains in the page).

Specify which one you want

cy.get('div:contains(What\'s your name?)').eq(1).should('be.visible')  // .and(contain) not needed

In case that quote in the text distorts the selection you may need to go with cy.get('div:contains(your name?)').eq(1).

Don't use cy.contains('What\'s your name?') it will only ever return the first one it finds.

The Facebook page is not very tester friendly, usually you can request the page elements have some test id's added so you can go directly to then.

Another way to tackle the anonymous popup stuff is just to grab the last thing added to the page, like

cy.get('body')
  .children()
  .last()
  .should('contain', 'What\'s your name?')
  .should('be.visible')
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!