I've encountered an issue with my code involving loading values into the array usageCategory within an inline function. Despite successfully adding values to the array inside the function, I am unable to print them outside it.
getAllUsageCategoryElements(){
var usageCategory: string[] = [];
var that=this;
// Extracting all droplist elements to validate from another page
this.addAdditionalCostDialogue.usageCategoryDropListContainer.all(by.tagName('li')).all(by.tagName("span")).each(function (element, index) {
element.getText().then(function (text){
//console.log("printing directly " + text);
// The above log statement works fine but pushing value to the array doesn't
that.usageCategory.push(text);
})
});
console.log("Size of the array is " + usageCategory.length);
usageCategory.forEach(element => {
console.log("Printing text " + element);
});
}
How can I resolve this issue and access the array values outside the inline function? Any assistance would be greatly appreciated.