ScreenshotNeo

BlogHow-to

How to automate website screenshots with Selenium in Python for a college project report

Use Selenium in Python to capture repeatable website screenshots for a college report, with setup, waits, evidence tips, and troubleshooting.

By the ScreenshotNeo team4 October 20268 min read

To automate a website screenshot with Selenium in Python, open the page with WebDriver, wait for the page state you need, and call driver.save_screenshot("screenshot.png"). That captures the current browser window as a PNG. For a report focused on one component, capture that element with element.screenshot(...). Set and record the browser window size, use an explicit wait tied to visible page content, and close the browser in a finally block.

This guide answers the practical question, “How do I take a screenshot of a website using Selenium in Python?” It covers repeatable capture, report evidence, common issues, and a browser-free API option.

1. Install Selenium and prepare a project

Use a current Python installation and install Selenium in the environment for this project:

python -m pip install selenium

Selenium’s official first-script guide demonstrates importing webdriver, starting Chrome, navigating with get, and quitting the browser. Browser startup also depends on your local browser and driver setup; consult Selenium’s current installation guidance if startup fails. The example below uses Chrome.

2. Capture a website screenshot with Python

Save this as capture_page.py. It creates an output directory, sets a known window size, navigates to the target URL, waits until the page heading is visible, saves a PNG, and always closes the browser.

from pathlib import Path

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait

URL = "https://example.com"
OUTPUT = Path("screenshots/example-page.png")
VIEWPORT = (1280, 900)

OUTPUT.parent.mkdir(parents=True, exist_ok=True)
driver = webdriver.Chrome()

try:
    driver.set_window_size(*VIEWPORT)
    driver.get(URL)

    # Choose a condition that proves the content you need is ready.
    WebDriverWait(driver, 10).until(
        EC.visibility_of_element_located((By.TAG_NAME, "h1"))
    )

    saved = driver.save_screenshot(str(OUTPUT))
    if not saved:
        raise OSError(f"Could not save screenshot to {OUTPUT}")
finally:
    driver.quit()

print(f"Saved {OUTPUT} at browser window size {VIEWPORT[0]}x{VIEWPORT[1]}")

Replace the URL and readiness locator with those for the page under study. The heading condition is only an example: a chart, result panel, or other visible element may better indicate that the screenshot will show the state your report discusses. Selenium documents that save_screenshot saves a PNG and returns a boolean indicating whether saving succeeded.

3. Choose what to capture

Current browser window

driver.save_screenshot("path.png") captures the current window or browsing context. It is suitable when the evidence should show the page as it appears in the visible browser area. It does not, by itself, promise an image of the entire scrollable document.

One element

When the report needs a focused image of a particular component, locate it and use the element screenshot method:

from pathlib import Path
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait

# Assumes driver has navigated to the page and its browser is open.
output = Path("screenshots/target-component.png")
output.parent.mkdir(parents=True, exist_ok=True)

element = WebDriverWait(driver, 10).until(
    EC.visibility_of_element_located((By.CSS_SELECTOR, ".result-panel"))
)
if not element.screenshot(str(output)):
    raise OSError(f"Could not save element screenshot to {output}")

Change .result-panel to a selector that identifies the evidence you need. Element capture makes the component prominent, while a window capture preserves surrounding page context. Selenium’s WebDriver interactions documentation shows the element screenshot pattern.

Full-page evidence

The standard current-window screenshot call is not a full-page capture API. If your assignment requires the whole scrollable document, choose a browser-specific method or a screenshot-stitching approach separately, then verify the resulting dimensions and coverage. Describe the method in your report; do not label a viewport image as full-page.

4. Make runs more repeatable

Website rendering can depend on the browser window dimensions. WebDriver provides window sizing controls, and Selenium’s documentation notes that screen resolution can affect how an application renders. For useful comparisons, keep these inputs constant:

  • Target: use the same URL and note redirects or query parameters that affect content.
  • Browser environment: record the browser, Selenium and Python versions, and operating system when relevant.
  • Window size: set a deliberate size such as 1280 × 900 and report it. This is the browser window size; it may not equal the screenshot’s CSS viewport in every environment.
  • Page state: wait for the same meaningful element or result on each run rather than relying on an arbitrary pause.
  • Capture scope: state whether each image shows the current window or one element.
  • Run details: note the capture date and any page conditions that could change, such as live data or rotating content.

These controls improve reproducibility but do not guarantee pixel-identical images across operating systems, browsers, fonts, or changing websites.

5. Present the screenshots in a college project report

  1. Keep the original PNG files as evidence. Use descriptive names such as home-desktop-1280x900.png.
  2. Write a figure caption that identifies the page, what the image demonstrates, and the configured window size.
  3. Explain the capture condition, such as waiting for the heading or result panel to become visible.
  4. If you crop, annotate, or otherwise edit a copy for readability, label the edits and retain the original.
  5. For layout comparisons, use the same URL, browser conditions, window dimensions, and page state for each capture.

For example: “Figure 2. Example page after the main heading became visible; Chrome window set to 1280 × 900; captured 4 October 2026.” Use the actual browser, date, and conditions from your own run.

6. Wait for the right page state

A page load finishing does not necessarily mean the particular content you need is visible. Selenium describes synchronization with browser state as a central challenge. An explicit wait makes the capture depend on a stated condition:

WebDriverWait(driver, 15).until(
    EC.visibility_of_element_located((By.ID, "report-result"))
)

Use a locator and condition tied to the content in the screenshot. Selenium’s expected conditions include visibility checks. Its waiting guidance warns that mixing implicit and explicit waits can produce unpredictable wait durations; prefer a consistent wait strategy and avoid adding an implicit wait on top of this explicit-wait example.

7. cURL, Python, and Node.js alternatives

The Selenium method above gives you control of a browser session. If you only need a screenshot file and do not need to manage a browser locally, ScreenshotNeo offers a one-request screenshot API. Its API accepts a URL and can return PNG, JPEG, WebP, or PDF. See the ScreenshotNeo API documentation for request options.

cURL

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp

Python

import requests

r = requests.get(
    "https://api.screenshotneo.com/v1/shot",
    params={"access_key": "YOUR_API_KEY", "url": "https://example.com"},
    timeout=90,
)
r.raise_for_status()
with open("shot.webp", "wb") as f:
    f.write(r.content)

Node.js

const q = new URLSearchParams({
  access_key: 'YOUR_API_KEY',
  url: 'https://example.com'
});
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
if (!res.ok) throw new Error(`Screenshot request failed: ${res.status}`);
const fs = await import('node:fs/promises');
await fs.writeFile('shot.webp', Buffer.from(await res.arrayBuffer()));

Or skip the browser setup

ScreenshotNeo is a website screenshot API and MCP server from ScreenshotNeo. Its clean-shot options accept cookie and consent banners like a visitor and remove more than 60 known consent platforms, newsletter popups, and chat widgets; each step can be turned off. Bot checks, blank pages, failed loads, timeouts, and cache hits cost nothing, and response headers say the page verdict and whether the shot was billed. An MCP server lets AI agents use take_screenshot, get_page_info, and capture_pdf. The free plan includes 1,000 shots a month with no card; paid plans start at $5 for 3,000 shots.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp

Use the [ScreenshotNeo API documentation](https://screenshotneo.com/docs/) to create the request and review its options, then sign up for 1,000 free screenshots a month with no card.

8. Troubleshooting

Symptom Likely cause What to do
Chrome does not start or WebDriver raises a startup error Browser installation, Selenium installation, or browser and driver setup is not ready in this environment. Confirm Selenium is installed in the active Python environment, verify Chrome is installed, and follow the current Selenium setup guidance for your platform.
NoSuchElementException or a wait times out The locator is wrong, the element has not appeared, or the page reached a different state. Inspect the page and selector, confirm the target URL and redirects, and wait for a meaningful condition on the intended content.
Screenshot is blank or misses expected content The capture ran before the relevant content became visible, or the page state differs from the expected one. Wait for the target content to be visible; check whether it is inside a frame or appears only after interaction, and ensure the capture follows those steps.
Screenshot is clipped or only shows the top of the page The standard WebDriver screenshot captures the current window, not necessarily the entire document. Capture the relevant element, scroll and capture sections, or use and verify a separate full-page technique if the assignment requires full-page evidence.
File is missing or the screenshot call returns false The output directory may not exist or the process cannot write to the chosen path. Create the parent directory, use a writable path, keep a .png filename for save_screenshot, and check its boolean return value.
Waits take unexpectedly long Implicit and explicit waits may be mixed, or the readiness condition cannot become true. Use one clear wait strategy, verify the locator and condition, and set a timeout appropriate to the page.
Browser stays open after an exception Cleanup is not reached in a straight-line script. Put capture work in try and call driver.quit() in finally.

9. Performance, reliability, and cost

For a small report, a sequential script with one browser session is usually easier to understand and reproduce than launching a new browser for each image. Reuse the session when capturing several pages, while waiting for the relevant state on every navigation. Always quit the browser when the batch completes or fails. Network speed, scripts, page complexity, and wait conditions affect capture duration, so do not treat a fixed sleep as proof that the page is ready.

Selenium itself is software; the sources reviewed do not establish a specific service price or runtime benchmark. Your practical costs are the machine and time needed to run the browser and maintain the environment. ScreenshotNeo’s listed plans are Free: 1,000 shots/month; Starter: $5 for 3,000; Growth: $15 for 15,000; Pro: $39 for 60,000; Scale: $99 for 250,000; Business: $249 for 1,000,000. Yearly billing gives two months free, and every feature is on every plan. Choose based on volume and whether an API or MCP workflow fits your project.

10. Frequently asked questions

Does Selenium save a screenshot as a PNG?

Yes. The documented save_screenshot method saves the current window screenshot as PNG; use a filename ending in .png.

Can I capture only a chart or panel?

Yes. Locate the element and call its screenshot method. This is useful when surrounding page content is not needed in the report.

Does changing the window size matter?

It can affect responsive rendering. Set and report a consistent size when comparing captures, while recognizing that the operating system and browser environment can still change rendering.

Can I claim my screenshots are pixel-identical across machines?

No. Consistent inputs improve repeatability, but they do not guarantee identical rendering across environments or changing page content.

Does the basic screenshot call capture the whole page?

It captures the current window context. Use a separately chosen and verified method when the assignment calls for a full-page image.