Snippet A
resultsBoard.findElements(By.css(mySelector)).then(function(elements) {
elements.forEach(function(val, idx) {
elements[idx].getText().then(function(text) {
console.log(text);
});
});
});
Snippet B
resultsBoard.findElements(By.css('mySelector')).then(function(elements) {
for (var idx = 0; idx < elements.length; idx++) {
elements[idx].getText().then(printText(text));
}
});
Snippet A successfully retrieves the text of all matched elements using the provided selector. Snippet B throws a
ReferenceError: text is not defined
So what causes this discrepancy and how can it be resolved?