Code 1
resultsBoard.findElements(By.css(mySelector)).then(function(elements) {
elements.forEach(function(val, idx) {
elements[idx].getText().then(function(text) {
console.log(text);
});
});
});
Code 2
resultsBoard.findElements(By.css('mySelector')).then(function(elements) {
for (var idx = 0; idx < elements.length; idx++) {
elements[idx].getText().then(printText(text));
}
});
Code 1 works well and retrieves the text of all the elements that matched my selector. Code 2 gives me a
ReferenceError: text is not defined
What is the difference? Why does this happen?