I’m encountering an issue using Puppeteer where the page.$$ method returns an empty array, despite the fact that the target website clearly has the desired elements when inspected with querySelectorAll in a browser console. I’ve attempted to use waitForSelector to ensure the elements load, but it only results in a timeout. Does anyone have insights into what might be causing this? Here is an alternative code snippet for clarity:
const fetchElements = async () => {
try {
const myBrowser = await puppeteer.launch({ args: ['--no-sandbox', '--disable-setuid-sandbox'] });
const myPage = await myBrowser.newPage();
await myPage.goto('https://example.com/sample');
const foundElements = await myPage.$$('[data-target="item"]');
console.log(foundElements);
await myBrowser.close();
} catch (err) {
console.error('Encountered an error:', err);
}
};
fetchElements();