I have the following code to retrieve all the span elements within a particular div during an iteration as shown below:
const getFruitElements = async () => {
const fruits = await page.$$(
`[aria-label="Banana Apple"]`
);
for (let fruit of fruits) {
const spanElements = await fruit.evaluate(() => {
return Array.from(document.querySelectorAll('span'));
});
console.log(spanElements); //This is always undefined even though there are spans
}
}
There are spans within the dev but I keep getting undefined
when logging the retrieved spans.
Is there something wrong with my evaluate function?