I have some code below to check if a checkbox is checked or not. Even if the checkbox is checked, it says that its not. Why does the code fail and how to fix it?
function isChecked(locator : string) : boolean {
let checked : boolean = false;
cy.get(locator).then(el){
if(el.val() === "on"){
checked = true;//Is actually true when element is checked.
}
}
return checked;//Is actually false when element is checked.
}
2
Answers
Rewrite your function in this way and check if it works: