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

85
Views
Cypress method for choosing an if section depending on a string

How can I write this method correctly in cypress so that when I call for example setToOffService('Online booking') it knows how to go to the correct if and call the appropriate id for that string.

I hope I have provided all the important details

 setToOffService(name: string) : void {
    
        cy.get('#Service_IsActive').then(($name) => {
    
            if ($name.text().includes('Service is available')) {
                cy.get('#Service_IsActive').click({force:true});
            }
            else if ($name.text().includes('Online booking')) {
                cy.get('#Service_AllowOnlineScheduling').click({force:true});
            }
        })
    }
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You can do something like this:

cy.get('#Service_IsActive').then(($ele) => {
  if ($ele.text().trim() == name) {
    cy.get('#Service_IsActive').click({force: true})
  } else if ($ele.text().trim() == name) {
    cy.get('#Service_AllowOnlineScheduling').click({force: true})
  }
})
about 4 years ago · Juan Pablo Isaza Report

0

It sounds like the name parameter should control which element to click?

setToOffService(name: string) : void {
    
  if (name === 'Service is available') {
    cy.get('#Service_IsActive').click();
  }
      
  if (name === 'Online booking') {
    cy.get('#Service_AllowOnlineScheduling').click();
  }
}


setToOffService('Service is available')  // clicks #Service_IsActive

setToOffService('Online booking')  // clicks #Service_AllowOnlineScheduling
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!