Pages

last() in protractor ?

How to use last() in protractor ?

When we have array(list) of web elements, we can click directly click last element using last() 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

last() protractor


Here we got 4 matches for checkbox elements.

so we need to use element.all(locator).
describe('Protractor - use last()', function () {
it('Code script to how to use last()', function () {
browser.get("https://keeplearners.blogspot.com/2018/03/Angular-elements.html");
var checkboxes = element.all(by.css("input[type='checkbox']"));
checkboxes.last().click();
console.log("Clicked last checkbox");
});
});
Output:
It will click last web element (Check Box 3)
protractor last()
last() in protractor

How to select last value in array protractor
last()
Please comment below to feedback or ask questions.

No comments:

Post a Comment

Please comment below to feedback or ask questions.