isSelected() in protractor ?
>> In protractor, we can get whether element (like radio buttons,checkboxes,...) is selected or not using isSelected().
>> isSelected() will return boolean values (true/false).
>> If value is true then element is selected and if value is false then element is not selected.
Please check below code script:
First write xpath with help of DOM
Here we have check box (Check Box 1) which is already in selected state.
describe('Protractor - use isSelected()', function () {
it('Code script to how to use isSelected()', function () {
browser.get("https://keeplearners.blogspot.com/2018/03/Angular-elements.html");
var checkbox = element(by.css("input[checked='checked'][type='checkbox']"));
var isSelect = checkbox.isSelected();
isSelect.then(function (value) {
console.log("is element selected=" + value);
});
});
});
Output:
It will return whether check box is selected or not.
protractor isSelected()
We can also write like a re-usable function like below:
describe('Protractor - use isSelected()', function () {
it('Code script to how to use isSelected()', function () {
browser.get("https://keeplearners.blogspot.com/2018/03/Angular-elements.html");
var checkbox = element(by.css("input[checked='checked'][type='checkbox']"));
var isSelect = isElementSelected(checkbox);
isSelect.then(function (value) {
console.log("value=" + value);
});
});
function isElementSelected(element) {
return element.isSelected().then(function (selected) {
console.log("is Element Selected=" + selected);
return selected;
});
}
});
Please comment below to feedback or ask questions.
No comments:
Post a Comment
Please comment below to feedback or ask questions.