Puppeteer

How to fill an input field using Puppeteer?

*爱你&永不变心* 提交于 2020-03-17 04:29:39
问题 I'm using Puppeteer for E2E test, and I am now trying to fill an input field with the code below: await page.type('#email', 'test@example.com'); It worked, but I found the email address was typed into the field one character by one character as if a real human being was typing. Is it possible to fill the input field with the email address all at one time? 回答1: Just set value of input like this: await page.$eval('#email', el => el.value = 'test@example.com'); Here is an example of using it on

Render Google Charts with Puppeteer

情到浓时终转凉″ 提交于 2020-03-05 03:10:00
问题 I am trying to figure ou the proper way to combine Puppeteer and the GoogleCharts library to render Bar charts and export a PNG image of the chart. The basic layout, mostly inspired by the Puppeteer documentation seems to be something like that, to create a new page with a canvas element. (async () => { const browser = await puppeteer.launch(); const page = await browser.newPage(); await page.setContent(` <!DOCTYPE html> <html> <body> <canvas id="chart" width="580" height="400"></canvas> <

Render Google Charts with Puppeteer

北城以北 提交于 2020-03-05 03:05:28
问题 I am trying to figure ou the proper way to combine Puppeteer and the GoogleCharts library to render Bar charts and export a PNG image of the chart. The basic layout, mostly inspired by the Puppeteer documentation seems to be something like that, to create a new page with a canvas element. (async () => { const browser = await puppeteer.launch(); const page = await browser.newPage(); await page.setContent(` <!DOCTYPE html> <html> <body> <canvas id="chart" width="580" height="400"></canvas> <

puppeteer wait for page update after button click (no navigation)

◇◆丶佛笑我妖孽 提交于 2020-03-03 06:49:44
问题 Trying puppeteer for the first time and it is amazing. I need to wait for a page to fetch and render new data after a button click. This does not cause a navigation (the url is the same) so the following code does not work (it gives timeout exception): await Promise.all([ myButton.click() page.waitForNavigation() ]) What's the correct way to wait for the page to fetch/render async data on click? 回答1: Assuming the DOM changes in some way, you can wait for a specific element or selector. Maybe

puppeteer wait for page update after button click (no navigation)

北城余情 提交于 2020-03-03 06:49:38
问题 Trying puppeteer for the first time and it is amazing. I need to wait for a page to fetch and render new data after a button click. This does not cause a navigation (the url is the same) so the following code does not work (it gives timeout exception): await Promise.all([ myButton.click() page.waitForNavigation() ]) What's the correct way to wait for the page to fetch/render async data on click? 回答1: Assuming the DOM changes in some way, you can wait for a specific element or selector. Maybe

How can I wait for network idle after click on an element in puppeteer?

让人想犯罪 __ 提交于 2020-02-25 00:41:50
问题 How can I wait for network idle after click on an element in puppeteer? const browser = await puppeteer.launch({headless: false}); await page.goto(url, {waitUntil: 'networkidle'}); await page.click('.to_cart'); //Click on element trigger ajax request //Now I need wait network idle(Wait for the request complete) await page.click('.to_cart'); UPD: No navigation after the element was clicked 回答1: I ran into a similar issue and found the workaround function on the Puppeteer Control networkidle

How can I wait for network idle after click on an element in puppeteer?

北战南征 提交于 2020-02-25 00:40:05
问题 How can I wait for network idle after click on an element in puppeteer? const browser = await puppeteer.launch({headless: false}); await page.goto(url, {waitUntil: 'networkidle'}); await page.click('.to_cart'); //Click on element trigger ajax request //Now I need wait network idle(Wait for the request complete) await page.click('.to_cart'); UPD: No navigation after the element was clicked 回答1: I ran into a similar issue and found the workaround function on the Puppeteer Control networkidle

How can I get the raw download size of a request using Puppeteer?

风格不统一 提交于 2020-02-05 06:12:09
问题 That is, the total amount of data downloaded across all resources (including video/media), similar to that returned by Chrome DevTools' Network tab. 回答1: There doesn't seem to be any way to do this as of January 2018 that works with all resource types (listening for the response event fails for videos), and that correctly counts compressed resources. The best workaround seems to be to listen for the Network.dataReceived event, and process the event manually: const resources = {}; page._client

How to download a pdf that opens in a new tab in puppeteer?

笑着哭i 提交于 2020-02-03 10:56:38
问题 I have a page with a button. When I click that button, it opens a PDF in a new tab. How can I download the PDF as a file with puppeteer? Maybe I can write a file with the buffer from the new tab. But I am not sure how. 回答1: Use puppeteer-extra node module. Puppeteer-extra const puppeteer = require('puppeteer-extra'); ... ... puppeteer.use(require('puppeteer-extra-plugin-user-preferences')({userPrefs: { download: { prompt_for_download: false, open_pdf_in_system_reader: true }, plugins: {

How to download a pdf that opens in a new tab in puppeteer?

放肆的年华 提交于 2020-02-03 10:54:05
问题 I have a page with a button. When I click that button, it opens a PDF in a new tab. How can I download the PDF as a file with puppeteer? Maybe I can write a file with the buffer from the new tab. But I am not sure how. 回答1: Use puppeteer-extra node module. Puppeteer-extra const puppeteer = require('puppeteer-extra'); ... ... puppeteer.use(require('puppeteer-extra-plugin-user-preferences')({userPrefs: { download: { prompt_for_download: false, open_pdf_in_system_reader: true }, plugins: {