Puppeteer page.evaluate querySelectorAll return empty objects

The values returned from evaluate function should be json serializeable. https://github.com/GoogleChrome/puppeteer/issues/303#issuecomment-322919968 the solution is to extract the href values from the elements and return it. await this.page.evaluate((sel) => { let elements = Array.from(document.querySelectorAll(sel)); let links = elements.map(element => { return element.href }) return links; }, sel);

Puppeteer – scroll down until you can’t anymore

Give this a shot: const puppeteer = require(‘puppeteer’); (async () => { const browser = await puppeteer.launch({ headless: false }); const page = await browser.newPage(); await page.goto(‘https://www.yoursite.com’); await page.setViewport({ width: 1200, height: 800 }); await autoScroll(page); await page.screenshot({ path: ‘yoursite.png’, fullPage: true }); await browser.close(); })(); async function autoScroll(page){ await page.evaluate(async () => { await … Read more

How to click on element with text in Puppeteer

Short answer This XPath expression will query a button which contains the text “Button text”: const [button] = await page.$x(“//button[contains(., ‘Button text’)]”); if (button) { await button.click(); } To also respect the <div class=”elements”> surrounding the buttons, use the following code: const [button] = await page.$x(“//div[@class=”elements”]/button[contains(., ‘Button text’)]”); Explanation To explain why using the text … Read more

Puppeteer wait until page is completely loaded

You can use page.waitForNavigation() to wait for the new page to load completely before generating a PDF: await page.goto(fullUrl, { waitUntil: ‘networkidle0’, }); await page.type(‘#username’, ‘scott’); await page.type(‘#password’, ‘tiger’); await page.click(‘#Login_Button’); await page.waitForNavigation({ waitUntil: ‘networkidle0’, }); await page.pdf({ path: outputFileName, displayHeaderFooter: true, headerTemplate: ”, footerTemplate: ”, printBackground: true, format: ‘A4’, }); If there is a … Read more