← Back to Discord Forum

`page.screenshot(full_page=True)` when done twice on the same page gives different image dimensions.

Am trying out Playwright, and an assert a.size == b.size of two screenshots is getting an AssertionError, since the sizes are different.

Ideally, I'd like to take a screenshot, checking the .size and then specify the .screenshot() to take a screenshot of that size again. That way there's no possibility of getting an AssertionError again.

I guess my question is.. How does someone set the .screenshot() length/width for a full_page screenshot?

This thread is trying to answer question "How does someone set the `.screenshot()` length/width for a `full_page` screenshot?"

0 replies


Sure, you can customize the size of a full-page screenshot in Playwright. You just need to use the clip option in the .screenshot() method. This option lets you define the x-coordinate, y-coordinate, width, and height of the clipping area for the image.

Here's a quick example:

await page.screenshot({
  path: 'screenshot.png',
  fullPage: true,
  clip: { x: 0, y: 0, width: 800, height: 600 }

In this code, fullPage is set to true to capture the entire scrollable page. The clip object is used to capture an area starting from coordinates (x=0, y=0) with a width of 800 pixels and a height of 600 pixels.

By tweaking the values in the clip object, you can adjust the size of your full-page screenshot to your liking.

Remember, this information is based on the current Playwright documentation. If there are any changes to the API or if you have specific requirements not covered here, it's best to refer to the official documentation.

Related Discord Threads

AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email luc@ray.run.