I need to wait each item, than call another function.
await readCSV(filename).then(fileArray => {
for (let element of fileArray) {
console.log(element)
searchItem(element) //<--- Wait each element will finish this function()
}
})
the function of searchItem() is:
async function searchItem(item) {
console.log('2) Avvio Browser for ' + item.codice_kromeda)
await page.goto('url_part1' + item.codice_kromeda + 'url_part2');
await page.waitForSelector('.si-search-result')
let list = await page.$$('.si-search-result');
console.log(list)
return true
}
>Solution :
Since searchItem() already returns a promise that resolves when the search is complete, you can simply restructure to properly use await:
const fileArray = await readCSV(filename);
for (let element of fileArray) {
console.log(element);
await searchItem(element);
}