Questions tagged [puppeteer]

Puppeteer is a Node.js library which provides a high-level API to control headless Chrome or Chromium over the DevTools Protocol. It can also be configured to use full (non-headless) Chrome or Chromium.

Puppeteer is a Node.js library which provides a high-level API to control headless Chrome or Chromium over the DevTools Protocol. It can also be configured to use full (non-headless) Chrome or Chromium. You can also use Puppeteer with Firefox Nightly (experimental support).


Puppeteer is mostly used for:

  1. Generate screenshots and PDFs of pages.
  2. Crawl an SPA and generate pre-rendered content (i.e. "SSR").
  3. Scrape content from websites.
  4. Automate form submission, UI testing, keyboard input, etc.
  5. Create an up-to-date, automated testing environment. Run your tests directly in the latest version of Chrome using the latest JavaScript and browser features.
  6. Capture a timeline trace of your site to help diagnose performance issues.

Resources:

Books:

Community:

5591 questions
355
votes
16 answers

Message "Async callback was not invoked within the 5000 ms timeout specified by jest.setTimeout"

I'm using Puppeteer and Jest to run some front end tests. My tests look as follows: describe("Profile Tab Exists and Clickable: /settings/user", () => { test(`Assert that you can click the profile tab`, async () => { await…
Asool
  • 7,423
  • 4
  • 25
  • 41
175
votes
6 answers

How can I pass variable into an evaluate function?

I'm trying to pass a variable into a page.evaluate() function in Puppeteer, but when I use the following very simplified example, the variable evalVar is undefined. I'm new to Puppeteer and can't find any examples to build on, so I need help passing…
Cat Burston
  • 1,893
  • 2
  • 9
  • 10
104
votes
9 answers

How to click on element with text in Puppeteer

Is there any method (didn't find in API) or solution to click on element with text? For example I have html:
Href text
Div text
And I want to click on…
Aleksandr Golubovskij
  • 1,115
  • 3
  • 9
  • 8
87
votes
9 answers

Puppeteer wait page load after form submit

I submit a form using the following code and i want Puppeteer to wait page load after form submit. await page.click("button[type=submit]"); //how to wait until the new page loads before taking screenshot? // i don't want this: // await…
redochka
  • 10,506
  • 10
  • 56
  • 72
80
votes
7 answers

puppeteer: wait N seconds before continuing to the next line

In puppeteer I would like to wait a defined time before going to the next line of code. I've tried to put a setTimeout in an evaluate function but it seems to be simply ignored console.log('before waiting'); await page.evaluate(async() => { …
Vivien Pipo
  • 3,876
  • 5
  • 21
  • 52
72
votes
6 answers

puppeteer: how to wait until an element is visible?

I would like to know if I can tell puppeteer to wait until an element is displayed. const inputValidate = await page.$('input[value=validate]'); await inputValidate.click() // I want to do something like that waitElemenentVisble('.btnNext…
Vivien Pipo
  • 3,876
  • 5
  • 21
  • 52
71
votes
7 answers

How to select an option from dropdown select

I can click the selector but my question is how to select one of the options from the dropdown list? await page.click('#telCountryInput > option:nth-child(4)') Click the option using CSS selector does not work. For example, select a country code…
X.Creates
  • 11,800
  • 7
  • 58
  • 98
67
votes
5 answers

How to fill an input field using Puppeteer?

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…
choasia
  • 8,394
  • 4
  • 34
  • 51
60
votes
4 answers

How to manage log in session through headless chrome?

I want to create a scraper that: opens a headless browser, goes to a url, logs in (there is steam oauth), fills some inputs, and clicks 2 buttons. My problem is that every new instance of headless browser clears my login session, and then I need…
Anton Kurtin
  • 603
  • 1
  • 5
  • 7
58
votes
6 answers

Node.js puppeteer - How to set navigation timeout?

I'm using node.js and puppeteer to get some data. Some of the files I'm opening are quite large ... and then I get an error: Error: our error { TimeoutError: Navigation Timeout Exceeded: 30000ms exceeded at Promise.then…
Philipp M
  • 2,534
  • 3
  • 19
  • 62
58
votes
7 answers

Puppeteer - scroll down until you can't anymore

I am in a situation where new content is created when I scroll down. The new content has a specific class name. How can I keep scrolling down until all the elements have loaded? In other words, I want to reach the stage where if I keep scrolling…
user1584421
  • 2,357
  • 7
  • 31
  • 54
53
votes
9 answers

Puppeteer wait until page is completely loaded

I am working on creating PDF from web page. The application on which I am working is single page application. I tried many options and suggestion on https://github.com/GoogleChrome/puppeteer/issues/1412 But it is not working const browser =…
51
votes
6 answers

Pressing Enter button in puppeteer

Pressing enter in puppeteer doesn't seem to have any effect. However, when I press other keys, it does what it should. This works: await page.press('ArrowLeft'); This doesn't: await page.press('Enter'); This is how the input looks like: Any…
elena
  • 2,820
  • 4
  • 19
  • 32
49
votes
7 answers

Opening local HTML file using Puppeteer

Is it possible to open a local HTML file with headless Chrome using Puppeteer (without a web server)? I could only get it to work against a local server. I found setContent() and goto() in the Puppeteer API documentation, but: page.goto: did not…
Anil Namde
  • 5,764
  • 9
  • 58
  • 96
49
votes
2 answers

Puppeteer: How to submit a form?

Using puppeteer, how could you programmatically submit a form? So far I've been able to do this using page.click('.input[type="submit"]') if the form actually includes a submit input. But for forms that don't include a submit input, focusing on the…
docta_faustus
  • 1,616
  • 2
  • 23
  • 35
1
2 3
99 100