How to emulate TAB key press in Puppeteer
In order to emulate a tab
key press in Puppeteer, use
await page.keyboard.press("Tab");
Full example:
// Minimal puppeteer example
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch({defaultViewport: {width: 1920, height: 1080}});
const page = await browser.newPage();
await page.goto('https://techoverflow.net', {waitUntil: 'domcontentloaded'});
// Press tab 10 times (effectively scrolls down on techoverflow.net)
for (let i = 0; i < 10; i++) {
await page.keyboard.press("Tab");
}
// Screenshot to verify result
await page.screenshot({path: 'screenshot.png'});
// Cleanup
await browser.close();
})();