I have a page that uses a basic bootstrap based Admin BSB Material Design layout
I am having difficulty getting a value from the checkboxes in this design.
Example checkbox that is 'checked':
I am seeing cypress having no luck finding the checkbox control even if i add a data-cypress="mycheckbx"
attribute.
So my questions is: how do I obtain the 'checked' property in this scenario?
Styles Used:
[type="checkbox"].filled-in:not(:checked)+label:before {
width: 0;
height: 0;
border: 3px solid transparent;
left: 6px;
top: 10px;
-webkit-transform: rotateZ(37deg);
transform: rotateZ(37deg);
-webkit-transform-origin: 20% 40%;
transform-origin: 100% 100%
}
[type="checkbox"].filled-in:not(:checked)+label:after {
height: 20px;
width: 20px;
background-color: transparent;
border: 2px solid #5a5a5a;
top: 0;
z-index: 0
}
[type="checkbox"].filled-in:checked+label:before {
top: 0;
left: 1px;
width: 8px;
height: 13px;
border-top: 2px solid transparent;
border-left: 2px solid transparent;
border-right: 2px solid #fff;
border-bottom: 2px solid #fff;
-webkit-transform: rotateZ(37deg);
transform: rotateZ(37deg);
-webkit-transform-origin: 100% 100%;
transform-origin: 100% 100%
}
[type="checkbox"].filled-in:checked+label:after {
top: 0;
width: 20px;
height: 20px;
border: 2px solid #26a69a;
background-color: #26a69a;
z-index: 0
}
Cypress handles checking and unchecking of checkbox with the help of its in built functions. For a checkbox, the tagname of the element should be input and the type attribute in the html code should be checkbox. check() − The check() command without argument checks all the checkboxes.
Open up your browser's inspector (Chrome Inspector, Firefox Firebug, etc), typically you would right click on near the checkboxes you need to select, then choose "Inspect Element". Once your inspector is up, switch to the 'Console' tab and enter a jQuery snippet like this. jQuery('#edit-menu-options input:checkbox').
Since none of the solutions above worked for me, I did this :
cy.get('#element').should('be.checked')
source : cypress documentation
The opposite (unchecked) assertion would be (see the official docs):
cy.get('#element').should('not.be.checked')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With