How to select an item in a list in Protractor

When we need to select an element in the list of element, we need to filter them out with the required criteria like visible text and then perform the action (click).

We use filter method to get the array of required elements and then perform the action on the array of elements in a callback function.

See the following sample code to understand better.

var editTemplateByName = function(templateName) {
    element.all(by.repeater('template in templates')).filter(function(elem, index) {
        return elem.getText().then(function(text) {
            return (text.indexOf(templateName)>-1);
        });
    }).then(function(filteredElements){
       element(by.buttonText('or Edit')).click();
    });
};

call the method: editTemplateByName('HTML');

0 comments:

Post a Comment