Skip to content

Screenshots ​

Introduction ​

Here is a quick way to capture a screenshot and save it into a file:

python
await page.screenshot(path="screenshot.png")
python
page.screenshot(path="screenshot.png")

Screenshots API accepts many parameters for image format, clip area, quality, etc. Make sure to check them out.

Full page screenshots ​

Full page screenshot is a screenshot of a full scrollable page, as if you had a very tall screen and the page could fit it entirely.

python
await page.screenshot(path="screenshot.png", full_page=True)
python
page.screenshot(path="screenshot.png", full_page=True)

Capture into buffer ​

Rather than writing into a file, you can get a buffer with the image and post-process it or pass it to a third party pixel diff facility.

python
# Capture into Image
screenshot_bytes = await page.screenshot()
print(base64.b64encode(screenshot_bytes).decode())
python
screenshot_bytes = page.screenshot()
print(base64.b64encode(screenshot_bytes).decode())

Element screenshot ​

Sometimes it is useful to take a screenshot of a single element.

python
await page.locator(".header").screenshot(path="screenshot.png")
python
page.locator(".header").screenshot(path="screenshot.png")

Released under the Apache 2.0 License.