• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

129
Views
Decision for a button by input value in cypress

I have the following code, which is responsible for the state of a checkbox slider (on/off).

When the button is on:

      <div _ngcontent-ofr-c662="" class="pull-right switch switch-small">
       <div _ngcontent-ofr-c662="" class="col-auto"><label _ngcontent-ofr-c662="" class="o-switch">
<input _ngcontent-ofr-c662="" type="checkbox" ng-reflect-model="true" ng-reflect-is-disabled="false" ng-reflect-options="[object Object]" class="ng-untouched ng-valid ng-dirty"><span _ngcontent-ofr-c662="" data-off="No" data-on="Yes" class="switch__obj"></span></label></div>
       <label _ngcontent-ofr-c662="" for="chkAllowCancelOrReschedule"></label>
    </div>

And when the button is off:

 <div _ngcontent-ofr-c662="" class="pull-right switch switch-small">
       <div _ngcontent-ofr-c662="" class="col-auto"><label _ngcontent-ofr-c662="" class="o-switch">
<input _ngcontent-ofr-c662="" type="checkbox" ng-reflect-model="false" ng-reflect-is-disabled="false" ng-reflect-options="[object Object]" class="ng-untouched ng-valid ng-dirty"><span _ngcontent-ofr-c662="" data-off="No" data-on="Yes" class="switch__obj"></span></label></div>
       <label _ngcontent-ofr-c662="" for="chkAllowCancelOrReschedule"></label>
    </div>

The only state that changes is that of the variable ng-reflect-model

How can I check this status and if it is true, press that button, and if it is off nothing happens and the test continues?

I hope I put all the details and didn't miss something.

Thank you.

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

0

Look at the value of the attribute using jQuery .attr(), like this

cy.get('input').then($el => {
  if ($el.attr('ng-reflect-model') === 'false') {
    cy.wrap($el).check()
  }
})
about 3 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 Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error