Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

wait for each element

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
}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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);
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading