I added an option to do scrollpagetobottom. with this npm.
const scrollPageToBottom = require('puppeteer-autoscroll-down');
after it, I have a loop that should click on many elements on the page But after I use the npm to scrolldown after one click I get this error:
Error: Node is either not visible or not an HTMLElement
(async () => {
try {
//Launching Puppeteer
const browser = await puppeteer.launch({
headless: false,
});
const page = await browser.newPage();
//going to new Page
await page.goto(
'https://translatewiki.net/wiki/Special:Translate?group=%21additions&language=fr&filter=%21translated&action=translate'
);
//waiting for the Js to load(DOM)
await page.waitForSelector('.tux-message');
await scrollPageToBottom(page, 5000, 2000);
console.log('finish scroll');
//Clicking on Questions to Load the suggestions
const texts = await page.$$(` div.eight.columns.tux-list-message`);
for (const text of texts) {
await new Promise((r) => setTimeout(r, 100));
await text.click();
}
} catch (err) {
console.log(err);
}
})();
I really don't know why it's happening hope for a master to help me.
Maybe try
await page.evaluate((element) => { element.click(); }, text);
instead of
await text.click();
If I recall correctly, puppeteer's elementHandle.click()
is a more complicated operation with some additional checks, so sometimes a simpler evaluated Web API element.click()
suffices when the former fails.