I am very new to TypeScript and protractor and would like to put all the extracted values from a drop list inside an array so that I can validate it from another page.
The problem is implementation above did not handle the async properly.
Size of the array is 0
list text from drop list is a
list text from drop list is b
list text from drop list is c
list text from drop list is d
Consider using await async, it would make a bunch of these issues much cleaner.
async getAllUsageCategoryElements() {
let usageCategory: string[] = [];
const elms = await element
.all(
by.xpath(
'//p-dropdown[@name='usageCategory']/div/div[3]/div/ul/li[*]/span'
)
);
for (var i = 0; i < elms.length; i++) {
usageCategory.push(await elms[i].getText());
}
return usageCategory;
}
From where you will be calling this function
const abc = await getAllUsageCategoryElements();
console.log('Size of the array is ' + abc.length);