I was trying to loop, compare based on a text and if matched click on the element.
I stumbled over the below post which was very helpful
Passing Protractor ElementFinder to deferred.fulfill() results in a promise containing a null value
Based on the answer provided in the above post, I implemented this
element.all(by.css('.classname')).map(function (elm, index) {
return {
elm: elm,
text: elm.getText(),
index: index
};
}).then(function (list) {
for (var i = 0; i < list.length; i++) {
if (list[i].text === 'DS_Emulator') {
return list[i].elm;
}
}
throw new error('Text not found');
}).then(function (elm) {
elm.click();
});
});
This made application exit out without any error. This is happening due to elm: elm in map.
if I modify my code as below, the application works fine.
element.all(by.css('.classname')).map(function (elm, index) {
return {
// elm: elm,
text: elm.getText(),
index: index
};
}).then(function (list) {
for (var i = 0; i < list.length; i++) {
if (list[i].text === 'DS_Emulator') {
return list[i].index;
// return list[i].elm;
}
}
throw new error('Text not found');
}).then(function (elm) {
// elm.click();
element.all(by.css('.classname')).then(function (items) {
items[elm].click();
});
});
Please help me understand where I am going wrong.