fnReturnElements: function(pathElems ){
var strArray= new Array();
selenium.waitForElements(pathElems).then(function(elements) {
for(i=0; i< elements.length;i++){
var a= selenium.getText(elements[i]);
a.then(function(value){
strArray.push(value);
});
}
});
console.log (strArray +" func");
return strArray;
}
I get blank in console for strArray outside the loop. Anything to do with promises? Here 'elements' are a list of webElements.
After going through the other posts about callbacks and asynchronous functions i made the following changes -
fnReturnElements: function(xpath){
var strArray= new Array();
return selenium.waitForElements(xpath).then(function(elements) {
for(i=0; i< elements.length;i++){
var a= selenium.getText(elements[i]);
a.then(function(value){
i++;
strArray.push(value);
console.log (i + value);
if ( i=== (elements.length*2 )){
return strArray;
}
});
}
});
}
Invoking the function as -
fnReturnElements ( xpath).then(function(value) {
console.log (value);
});
But still getting 'undefined' . [a.then(function(value)] line with a return before it, also does not change the output. Any pointers what i am doing wrong here?