question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Screenshots of Multiple Elements on Page Result in Some Blank Screenshots

See original GitHub issue

Steps to reproduce

Tell us about your environment:

What steps will reproduce the problem?

I’m trying to take screenshots of a series of HTML elements. The first couple of elements in the series are captured without a problem. However, the third through the tenth appear blank. The screenshots have the right dimensions, but they have no content. Interestingly, if I take a screenshot of the full page, the elements appear fine.

Please include code that reproduces the issue.

const puppeteer = require('puppeteer');

const captureScreenshotsOfElements = async (elements) => {
  let i = 0;
  for (const element of elements) {
    await element.screenshot({ path: `tmp/${i}.png` });
    i += 1;
  }
};

//
(async () => {
  const browser = await puppeteer.launch({headless: false});
  try {
    const page = await browser.newPage();
    await page.setViewport({width: 1200, height: 1200});
    await page.goto('http://graasp.eu/ils/5a9d467e45aca55d33eafce6/?lang=en&printPreview', { waitUntil: 'networkidle0' });

    // wait five more seconds just in case
    await page.waitFor(5000);

    // dismiss cookie banner
    const dismissCookiesMessageButton = 'a.cc-dismiss';
    await page.waitForSelector(dismissCookiesMessageButton);
    await page.click(dismissCookiesMessageButton);

    // print screenshot
    await page.screenshot({path: 'tmp/fullPage.png', fullPage: true});

    const gadgets = await page.$$('div.gadget-content');
    await captureScreenshotsOfElements(gadgets, page);

    await browser.close();
  } catch (err) {
    console.error(err);
    browser.close();
  }

})();

In short I do the following:

  1. Load up the page.
  2. Dismiss cookie banner.
  3. Take screenshot of full page.
  4. Select the elements and capture screenshots of each of them.

If have switched steps 3 and 4 around and get the same result.

What is the expected result?

All of the screenshots of the elements show the element content.

What happens instead?

The first three element screenshots show the content. The rest of them are empty.

I believe that there is a small moment after the viewport changes where the element is blank and that’s when the screenshot is take. Is there anyway of waiting a bit before taking the screenshot of the element?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:7
  • Comments:6

github_iconTop GitHub Comments

3reactions
joeldouglasscommented, May 1, 2018

I was able to work around this by setting the viewport height to a very large number (e.g. 1000000).

0reactions
stale[bot]commented, Jul 26, 2022

We are closing this issue. If the issue still persists in the latest version of Puppeteer, please reopen the issue and update the description. We will try our best to accomodate it!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to capture the screenshot of a specific element rather ...
We can get the element screenshot by cropping entire page screenshot as below: driver.get("http://www.google.com"); WebElement ele = driver.
Read more >
How to capture/take Selenium Screenshot as Full ... - Tools QA
Why is Screenshot required in Automation testing? How to take a Selenium screenshot Full page & of a particular element in Selenium ?...
Read more >
GoFullPage - Full Page Screen Capture
Capture a screenshot of your current page in entirety and reliably—without requesting any extra permissions!
Read more >
Full Page Screenshots in Browsers | CSS-Tricks
A full page screenshot captures the entire website even if it needs to be scrolled around to see all of it. You could...
Read more >
Take a screen capture and use it as an image in an email
Take a screenshot of a document, video, website, or mobile app ... of the first page and links the image to the PDF...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found