Scroll down pop up window list using puppeteer

  javascript, node.js, puppeteer

Whenever I need to scroll down a page using puppeteer i’ve been using this solution:

async function autoScroll(page) {
    await page.evaluate(async () => {
        await new Promise((resolve, reject) => {
            var totalHeight = 0;
            var distance = 100;
            var timer = setInterval(() => {
                var scrollHeight = document.body.scrollHeight;
                window.scrollBy(0, distance);
                totalHeight += distance;

                if (totalHeight >= scrollHeight) {
                    clearInterval(timer);
                    resolve();
                }
            }, 100);
        });
    });
}

Here is the source: https://github.com/chenxiaochun/blog/issues/38

I’m running into a different situation however where I need to scroll down a pop up window. It’s a flexbox window which pops up over the center of the page that contains a scroll bar on the side of the window which of course can be used to manually scroll down the list of items. I want to find a way to scroll down this list using puppeteer but this script seems to only apply to scrolling the entire page.

How should I best achieve this in puppeteer?

Source: Ask Javascript Questions

LEAVE A COMMENT