ScreenshotNeo

BlogComparisons

Playwright vs Selenium for Capturing Google SERP Screenshots

Compare Playwright and Selenium for Google SERP screenshots, with runnable examples, capture controls, troubleshooting, and guidance on repeatable results.

By the ScreenshotNeo team4 October 202610 min read

Short answer: Both Playwright and Selenium can capture a Google search results page (SERP). Playwright is a practical choice when you want screenshot controls in the capture call and built-in visual comparison support through Playwright Test. Selenium is a practical choice when your automation already uses WebDriver or needs to fit its cross-browser automation model. The available documentation does not establish that either is universally faster or more reliable for Google SERPs.

A SERP screenshot records what a particular browser session displayed at a particular time. It is not structured ranking data, and it does not establish that results are stable across locations, accounts, languages, devices, or time. This guide shows how to capture and compare the image while recording the context needed to interpret it.

1. Decide what you need to capture

Before choosing a framework, define what “the SERP” means for your use case. A visible viewport is usually suitable for a report or visual check. A full-page capture includes content below the fold, while an element capture can focus on a result container. These choices produce different images, so make the scope explicit.

  • Viewport: the currently visible browser area. Use this when the screenshot should reflect what a user sees without scrolling.
  • Full page: the document from top to bottom. It can include results or page sections outside the initial viewport.
  • Element: a selected page element, such as a result region. This requires a selector that matches the page as rendered in that session.
  • Scrolling sequence: multiple viewport captures taken as the page is scrolled. This is useful when a single tall image is unsuitable, but the sequence and scroll positions should be recorded.

Google’s interface and results can vary with the query, location, language, account or session state, viewport, and time. Fix and record the inputs you control; doing so does not make the SERP universal or eliminate all variation.

2. Playwright vs Selenium at a glance

Need Playwright Selenium
Save a page screenshot Page screenshot API can save to disk or return image bytes. WebDriver supports screenshots of the current browsing context.
Capture one element Use a locator’s screenshot method. Use the WebElement screenshot method.
Capture controls Documented options include full-page capture, image format, pixel scale, masks, animation handling, and stylesheets. The cited WebDriver documentation establishes page and element capture. The basic API does not expose the same set of screenshot options in one call.
Visual regression Playwright Test includes screenshot comparisons and waits for consecutive screenshots to stabilize before comparing. The cited Selenium screenshot documentation describes capture APIs, not an equivalent built-in visual comparison assertion.
Browser strategy Official API examples cover Chromium, WebKit, and Firefox. Selenium describes WebDriver as an interface intended to support interchangeable browser automation across major browsers. That design goal does not mean every browser behaves identically.

Playwright’s capture options are useful when the screenshot itself needs masking, animation handling, or full-page scope. Selenium’s capture methods are sufficient for many straightforward page and element screenshots. Choose based on your existing stack, needed capture controls, and comparison workflow, rather than assuming a speed or reliability winner.

References: Playwright Page API, Playwright visual comparisons, Selenium screenshots, and Selenium project documentation.

3. Capture a Google SERP with Playwright

The following Node.js example launches Chromium, opens a search URL, waits for the document to load, and saves a viewport screenshot. It uses a fixed viewport and locale to make the capture context explicit. A wait condition is not a guarantee that every dynamic page element has finished changing.

import { chromium } from 'playwright';

const query = 'playwright screenshot';
const searchUrl = `https://www.google.com/search?q=${encodeURIComponent(query)}`;
const browser = await chromium.launch({ headless: true });
const context = await browser.newContext({
  viewport: { width: 1365, height: 900 },
  locale: 'en-US',
  timezoneId: 'UTC'
});
const page = await context.newPage();

try {
  await page.goto(searchUrl, { waitUntil: 'domcontentloaded', timeout: 60000 });
  await page.locator('body').waitFor({ state: 'visible', timeout: 15000 });
  await page.screenshot({ path: 'serp.png', fullPage: false });
  console.log(JSON.stringify({
    url: page.url(),
    title: await page.title(),
    capturedAt: new Date().toISOString(),
    viewport: { width: 1365, height: 900 }
  }, null, 2));
} finally {
  await browser.close();
}

Save it as capture-serp.mjs, install Playwright with npm install -D playwright, install its browser with npx playwright install chromium, then run node capture-serp.mjs.

Playwright capture options

Pass screenshot options to page.screenshot() to control the output. Options include fullPage, type (PNG or JPEG), JPEG quality, scale (CSS pixels or device pixels), mask for covering selected locators, animations, and style for injected CSS. Check the current Page API reference for option details and supported combinations. For example, to save a full-page JPEG, use await page.screenshot({ path: 'serp.jpg', fullPage: true, type: 'jpeg', quality: 85 });.

For a single element, use a locator: await page.locator('main').screenshot({ path: 'serp-main.png' });. Selectors depend on the rendered page; inspect the page and confirm the locator matches the intended region rather than relying on an assumed permanent selector.

4. Capture a Google SERP with Selenium

This Python example uses Selenium WebDriver with Chrome. It records the viewport dimensions and page title, then saves a screenshot of the current browsing context.

from datetime import datetime, timezone
from urllib.parse import quote_plus
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait

query = 'playwright screenshot'
search_url = 'https://www.google.com/search?q=' + quote_plus(query)
options = Options()
options.add_argument('--headless')
options.add_argument('--window-size=1365,900')

with webdriver.Chrome(options=options) as driver:
    driver.get(search_url)
    WebDriverWait(driver, 15).until(
        lambda browser: browser.execute_script(
            'return document.readyState'
        ) in ('interactive', 'complete')
    )
    driver.save_screenshot('serp.png')
    print({
        'url': driver.current_url,
        'title': driver.title,
        'captured_at': datetime.now(timezone.utc).isoformat(),
        'window_size': driver.get_window_size()
    })

Save as capture_serp.py, install the Python package with python -m pip install selenium, ensure a compatible Chrome browser and driver are available for your Selenium setup, and run python capture_serp.py. Selenium’s current setup guidance explains driver management and browser requirements.

Selenium element capture

Find the element you want and call its screenshot method:

from selenium.webdriver.common.by import By

results_region = driver.find_element(By.TAG_NAME, 'main')
results_region.screenshot('serp-results.png')

Put this inside the WebDriver session after navigation. If the element is not present, inspect the actual page and wait for the intended element. Avoid treating a selector as a stable Google interface contract.

5. Make captures comparable

  1. Fix the inputs: record the exact query, capture time, viewport, browser and version, operating environment, locale, timezone, and session or sign-in state.
  2. Use the same setup: keep browser version, operating system, headless mode, viewport, fonts, and relevant settings consistent when comparing images.
  3. Wait for the state you intend to document: use a meaningful condition, such as a visible page region. A fixed sleep can waste time or still finish before a page is ready.
  4. Keep evidence together: store the original image with a metadata file containing the inputs and timestamp.
  5. Review differences: record any visual-comparison tolerance and inspect the actual images. A pixel difference can reflect rendering variation as well as a meaningful page change.

Playwright’s visual comparison documentation warns that browser rendering can vary with the host operating system, browser version, settings, hardware, power source, headless mode, and other factors. It recommends using the same environment that produced the baseline when consistency matters. A repeatable setup reduces avoidable differences but cannot freeze Google’s results or interface.

To add a visual assertion to a Playwright Test project, use the documented screenshot assertion, for example await expect(page).toHaveScreenshot('serp.png');, after the page reaches the state you intend to compare. Consult the visual comparisons documentation for baseline generation, options, and environment guidance.

6. Performance, reliability, and cost

Performance

Neither framework is established by the cited sources as faster for Google SERP capture. Runtime depends on browser startup, host resources, navigation, page behavior, screenshot scope, and whether the browser is reused across captures. A full-page image or high pixel scale can produce a larger image than a viewport capture. For a fair internal comparison, keep the browser, host, query, viewport, wait condition, and capture scope the same, and report your own measurements rather than generalizing them.

Reliability

Reliability has two parts: whether automation reaches the intended page state and whether the resulting image is comparable. Google pages may vary by context, and automated access can encounter changing page behavior. Record failures and metadata, use explicit waits, and preserve the raw screenshot. Do not claim a SERP is representative of all users based on one session.

Cost

Playwright and Selenium are browser automation frameworks; this workflow also uses browser and host resources. The dossier provides no comparative operating-cost figures. Account for your own compute, storage, and maintenance needs. For repeated captures, reuse a browser process where your architecture permits and set a clear retention policy for images and metadata.

7. Troubleshooting

Symptom Likely cause Fix
Navigation times out The page did not reach the chosen load condition within the timeout, or navigation behavior changed. Check the final URL and page state, choose an appropriate navigation condition, and wait for the specific content you need. Raising the timeout alone may hide the underlying issue.
Screenshot is blank or incomplete The capture ran before the intended content appeared, or the selected region was not visible. Wait for a meaningful element or state, confirm the page title and URL, and inspect the saved image. Capture again only after confirming the page reached the intended state.
Playwright browser executable is missing The package is installed but its browser has not been installed in the environment. Run npx playwright install chromium in that environment and check the official setup instructions.
Selenium cannot start Chrome Chrome or a compatible driver is unavailable, or the execution environment lacks required browser dependencies. Check the Selenium setup guidance, installed browser, driver setup, and environment logs. Keep the browser and driver configuration consistent across runs.
Element lookup fails The selector does not match the rendered page, or the element has not appeared yet. Inspect the actual DOM, choose a locator for the intended region, and wait for it to be present or visible.
Images differ between runs The SERP or rendering environment changed, including browser version, viewport, session, locale, or page content. Compare metadata first, keep the capture environment fixed, and review the images before treating a diff as a product change.
Results differ from another machine The captures may use different location, language, account state, viewport, time, or other session context. Record and align controllable inputs. Describe the screenshots as captures from those contexts, not as a universal SERP.

8. Google Search screenshot guidance

If you plan to publish a screenshot, consult Google’s Search brand guidelines. They say print use of Search screenshots for educational or instructional purposes does not require permission, and advise presenting Search naturally without altering its interface or results and keeping it supplemental. That guidance is limited to the stated context; it is not blanket permission for every automated access, publication, or reuse scenario.

A screenshot is visual evidence, not structured result data. If your goal is ranking measurement or machine-readable SERP analysis, determine an appropriate data collection method and separately check current terms, access rules, and applicable law. The cited brand guidance is not a complete statement about automated access or scraping.

9. Or skip the browser setup

ScreenshotNeo is a website screenshot API and MCP server from Yorker Media. One request returns an image or PDF, so you do not need to install or manage a browser for a basic capture. See the ScreenshotNeo API documentation.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url='https://www.google.com/search?q=playwright+screenshot' -o shot.webp
import requests

r = requests.get(
    "https://api.screenshotneo.com/v1/shot",
    params={
        "access_key": "YOUR_API_KEY",
        "url": "https://www.google.com/search?q=playwright+screenshot"
    },
    timeout=90
)
open("shot.webp", "wb").write(r.content)
const q = new URLSearchParams({
  access_key: 'YOUR_API_KEY',
  url: 'https://www.google.com/search?q=playwright+screenshot'
});
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
if (!res.ok) throw new Error(`Screenshot request failed: ${res.status}`);
const bytes = new Uint8Array(await res.arrayBuffer());
await (await import('node:fs/promises')).writeFile('shot.webp', bytes);

ScreenshotNeo removes cookie banners, newsletter popups, and chat widgets before capture. Bot checks, blank pages, and failed loads are never billed. An MCP server lets AI agents use screenshot tools. The free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000. Each feature is available on every plan. See the docs for request options and response details, including page verdict and billing headers.

Create a free ScreenshotNeo account for 1,000 screenshots a month with no card.

10. FAQ

Can Selenium take a screenshot of Google search results?

Yes. WebDriver supports screenshots of the current browsing context and individual elements. The Python example above saves a page screenshot.

Does Playwright or Selenium guarantee the same Google results each time?

No. A capture documents one browser session and context. Recording inputs improves interpretation, but does not make results universal or immutable.

Should I use a screenshot to track rankings?

A screenshot is an image, not structured ranking data. Use it when the visual page is what you need to document; evaluate a suitable data collection method for machine-readable analysis.

Can I publish Google Search screenshots?

Check the intended use against Google’s current Search guidelines and other applicable requirements. The cited print guidance is specifically about educational or instructional use and should not be generalized.