How to use first() in protractor ?
When we have array(list) of web elements, we can click directly click first element using first() method without using array index(es).
When we have array(list) of web elements, we will declare web element using locator element.all(locator).
Please check below code script:
First write xpath with help of DOM
Here we got 4 matches for checkbox elements.
so we need to use element.all(locator).
describe('Protractor - use first()', function () {
it('Code script to how to use first()', function () {
browser.get("https://keeplearners.blogspot.com/2018/03/Angular-elements.html");
var checkboxes = element.all(by.css("input[type='checkbox']"));
checkboxes.first().click();
console.log("Clicked first checkbox");
});
});
Output:
It will click first web element (Check all)
first() in protractor Please comment below to feedback or ask questions.
No comments:
Post a Comment
Please comment below to feedback or ask questions.