Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

For a Kotlin/JVM program, automate a real browser with Selenium WebDriver or Playwright, wait for the page to finish rendering, and save the captured bytes or file. Selenium uses the WebDriver TakesScreenshot interface; Playwright exposes Java screenshot options that Kotlin can call directly. Use a viewport shot for what is currently visible, a full-page shot for the complete scrollable document, and an element shot for one component.

Choose the capture method

Need Best fit Kotlin API
Visible browser viewport Selenium or Playwright Driver screenshot or page.screenshot()
Entire scrollable page Playwright has an explicit option; Selenium support depends on the driver setFullPage(true) in Playwright
One component Either tool when the implementation supports element capture WebElement screenshot or locator screenshot
Image in memory Playwright or Selenium base64 output ByteArray or OutputType.BASE64
Command-line capture Playwright CLI screenshot command and flags

Take a screenshot with Selenium in Kotlin

Selenium’s TakesScreenshot interface is implemented by drivers that can capture a screenshot. The documented Java API is directly usable from Kotlin.

Viewport screenshot

import org.openqa.selenium.OutputType
import org.openqa.selenium.TakesScreenshot
import org.openqa.selenium.chrome.ChromeDriver
import java.nio.file.Files
import java.nio.file.StandardCopyOption
import java.nio.file.Path

fun main() {
    val driver = ChromeDriver()
    try {
        driver.get("https://example.com")
        val temporary = (driver as TakesScreenshot)
            .getScreenshotAs(OutputType.FILE)
        Files.copy(
            temporary.toPath(),
            Path.of("website.png"),
            StandardCopyOption.REPLACE_EXISTING
        )
    } finally {
        driver.quit()
    }
}

getScreenshotAs(OutputType.FILE) returns a temporary file, so copy it to a destination before the driver session ends. The API can also return a base64 representation when you need to upload the image rather than write it locally.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Capture one element

import org.openqa.selenium.By
import org.openqa.selenium.OutputType
import org.openqa.selenium.TakesScreenshot

val hero = driver.findElement(By.cssSelector(".hero"))
val heroFile = (hero as TakesScreenshot).getScreenshotAs(OutputType.FILE)
Files.copy(
    heroFile.toPath(),
    Path.of("hero.png"),
    StandardCopyOption.REPLACE_EXISTING
)

Element capture requires an element implementation that supports TakesScreenshot. If it is unsupported by the selected driver, capture the viewport and crop it in your own image-processing step.

#1 Best Overall
Sale
Samsung Galaxy A17 5G Smart Phone 128GB US 1 Yr Manufacturer Warranty Black
  • YOUR CONTENT, SUPER SMOOTH: The ultra-clear 6.7" FHD+ Super AMOLED display of Galaxy A17 5G helps bring your content to life, whether you're scrolling through recipes or video chatting with loved ones.¹
  • LIVE FAST. CHARGE FASTER: Focus more on the moment and less on your battery percentage with Galaxy A17 5G. Super Fast Charging powers up your battery so you can get back to life sooner.²
  • MEMORIES MADE PICTURE PERFECT: Capture every angle in stunning clarity, from wide family photos to close-ups of friends, with the triple-lens camera on Galaxy A17 5G.
  • NEED MORE STORAGE? WE HAVE YOU COVERED: With an improved 2TB of expandable storage, Galaxy A17 5G makes it easy to keep cherished photos, videos and important files readily accessible whenever you need them.³
  • BUILT TO LAST: With an improved IP54 rating, Galaxy A17 5G is even more durable than before.⁴ It’s built to resist splashes and dust and comes with a stronger yet slimmer Gorilla Glass Victus front and Glass Fiber Reinforced Polymer back.

What Selenium actually captures

A conformant WebDriver follows the W3C WebDriver specification. For a non-conformant driver, Selenium documents a best-effort order: entire page, current window, visible current frame, then the entire display. Therefore, do not assume that a driver-level screenshot is always a complete, full-page image; verify the result with the browser and driver combination you deploy.

Take a screenshot with Playwright in Kotlin

Playwright’s Java API is Kotlin-compatible. Create a browser, open a page, wait for the navigation and dynamic content your site needs, then call Page.ScreenshotOptions.

Viewport screenshot saved to disk

import com.microsoft.playwright.Playwright
import com.microsoft.playwright.BrowserType
import com.microsoft.playwright.Page
import java.nio.file.Paths

fun main() {
    Playwright.create().use { playwright ->
        playwright.chromium().launch(
            BrowserType.LaunchOptions().setHeadless(true)
        ).use { browser ->
            val page = browser.newPage()
            page.navigate("https://example.com")
            page.screenshot(
                Page.ScreenshotOptions()
                    .setPath(Paths.get("screenshot.png"))
            )
        }
    }
}

Full-page screenshot

page.screenshot(
    Page.ScreenshotOptions()
        .setPath(Paths.get("full-page.png"))
        .setFullPage(true)
)

Playwright defines a full-page screenshot as the complete scrollable page, as if it fit on a very tall screen. This is different from a viewport shot, which includes only the currently visible area.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Keep the image in memory

val bytes: ByteArray = page.screenshot()

Capture a single element

page.locator(".header").screenshot(
    com.microsoft.playwright.Locator.ScreenshotOptions()
        .setPath(Paths.get("header.png"))
)

Locators wait for the target to be resolved according to Playwright's normal locator behavior. For animations or late-loading content, add an explicit readiness condition before the screenshot.

Rank #2
Tracfone Motorola Moto G 2025, 64GB, Saphire Blue (Locked to
  • Carrier: This phone is locked to Tracfone, which means this device can only be used on the Tracfone wireless network. Tracfone plan required, activating is easy, just 3 steps.
  • DISPLAY: Immersive viewing on a 6.7-inch super-bright 120Hz display with powerful stereo speakers and Bass Boost for cinematic entertainment.
  • CAMERA SYSTEM: Advanced 50MP Quad Pixel camera captures sharp, detailed photos and videos in any lighting condition
  • PERFORMANCE: Lightning-fast 5G connectivity paired with a powerful processor and RAM Boost for smooth multitasking.
  • BATTERY LIFE: Long-lasting 5000mAh battery with TurboPower charging technology delivers hours of power in minutes.

Make the capture deterministic

Wait for navigation and content

Calling the screenshot immediately after starting navigation can produce a blank, incomplete, or unstyled image. Wait for navigation to complete and for an application-specific selector, data request, or delay that proves the content is ready. A selector wait is usually more reliable than an arbitrary sleep.

Choose the right scope

  • Viewport: documents exactly what a user sees at the selected window size.
  • Full page: includes the complete scrollable document and is useful for archives and review.
  • Element: isolates a card, header, chart, or other component.

Control rendering conditions

Visual output can vary with operating-system version, browser version, browser settings, hardware, power source, and headless mode. Keep baseline and comparison runs in the same environment for visual regression testing. Use the same viewport, browser engine, fonts, time zone, data, and animation state whenever those details matter.

Handle long or dynamic pages

  • Lazy-loaded images may not exist until the page is scrolled. Trigger the site's loading behavior before a full-page capture, or use a capture service that explicitly loads lazy images.
  • Sticky headers, animated transitions, clocks, ads, and randomized content can create inconsistent images. Disable animations or wait for a stable state when the page permits it.
  • Cross-origin iframes and browser permission prompts can remain outside your control. Treat them as part of the chosen browser's rendering result, not as guaranteed pixels.

Use the Playwright command line

The Playwright CLI is useful when Kotlin is not needed for a particular capture or when a build job should run a simple command. Its screenshot command supports the viewport, a selected target, a custom filename, image type, full-page capture, and high-resolution output.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
playwright screenshot https://example.com --filename=shot.png
playwright screenshot https://example.com --full-page --filename=page.png
playwright screenshot https://example.com screenshot-target --type=jpeg --filename=target.jpg
playwright screenshot https://example.com --type=webp --hires --filename=retina.webp

If no type is supplied, the format is inferred from the filename extension and defaults to PNG. Check the CLI's installed version for the exact target-selector syntax in your environment; the documented form is screenshot [target].

Rank #3
Sale
Samsung Galaxy A17 5G Smart Phone 128GB, US 1 Yr Manufacturer Warranty Blue
  • YOUR CONTENT, SUPER SMOOTH: The ultra-clear 6.7" FHD+ Super AMOLED display of Galaxy A17 5G helps bring your content to life, whether you're scrolling through recipes or video chatting with loved ones.¹
  • LIVE FAST. CHARGE FASTER: Focus more on the moment and less on your battery percentage with Galaxy A17 5G. Super Fast Charging powers up your battery so you can get back to life sooner.²
  • MEMORIES MADE PICTURE PERFECT: Capture every angle in stunning clarity, from wide family photos to close-ups of friends, with the triple-lens camera on Galaxy A17 5G.
  • NEED MORE STORAGE? WE HAVE YOU COVERED: With an improved 2TB of expandable storage, Galaxy A17 5G makes it easy to keep cherished photos, videos and important files readily accessible whenever you need them.³
  • BUILT TO LAST: With an improved IP54 rating, Galaxy A17 5G is even more durable than before.⁴ It’s built to resist splashes and dust and comes with a stronger yet slimmer Gorilla Glass Victus front and Glass Fiber Reinforced Polymer back.

Kotlin/JS browser testing

Kotlin's official JavaScript project setup includes an experimental browser-testing DSL. It uses Playwright as the browser driver and distribution manager, with Chromium, Firefox, and WebKit runners. Browser binaries can be installed through the playwright install command. This route is appropriate when the test itself is Kotlin/JS rather than a JVM service. Treat the DSL as experimental and verify its setup instructions for the Kotlin version used by your project.

Selenium or Playwright?

Decision point Selenium Playwright
API style TakesScreenshot and OutputType Page.ScreenshotOptions, locator screenshots, and byte arrays
Full-page API Driver-dependent behavior; no universal guarantee in the cited API Explicit setFullPage(true)
Element capture Supported when the WebElement implementation supports TakesScreenshot Documented locator screenshot method
CLI No equivalent screenshot CLI described here Dedicated command with filename, type, full-page, and high-resolution flags
Best starting point Existing WebDriver test suites and infrastructure New projects needing explicit page, locator, and CLI screenshot controls

Choose the tool already used by your tests if integration effort is the deciding factor. Choose Playwright when full-page and locator capture are central requirements. Whichever you select, pin the execution environment for pixel-sensitive comparisons.

Common failures and fixes

The file is blank or only partly rendered

Cause: the screenshot ran before navigation, JavaScript, fonts, or lazy content finished. Fix: wait for navigation and a page-specific ready selector; for long pages, trigger lazy loading before capture.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The image is viewport-only

Cause: a viewport screenshot was requested, or the driver does not implement full-page capture. Fix: use Playwright's setFullPage(true), or implement a driver-specific scroll-and-stitch workflow after confirming its limitations.

Rank #4
Sale
Samsung Galaxy S26 Ultra, Unlocked Android Smartphone, 512GB, Black
  • PRIVACY DISPLAY: Automatically hide your screen from those beside you. The built-in privacy display can be preset¹ to turn on when receiving notifications, typing passwords, or using specific apps
  • TYPE IT IN. TRANSFORM IT FAST: Enhance any shot in seconds on your smartphone by using Photo Assist² with Galaxy AI.³ Add objects, restore details, or apply new styles by simply typing or tapping
  • NIGHTS, CAPTURED CLEARLY: From gigs to city lights, record and capture moments after dark with clarity using Nightography so your photos and videos stay crisp and clear on your Samsung Galaxy
  • MAKE IT. EDIT IT. SHARE IT: Turn everyday moments into something personal with creative tools built right into your mobile phone, whether it’s a special contact photo, custom wallpaper, an invitation or more⁴
  • HELP THAT KEEPS UP: Stay in the moment while Now Nudge with Galaxy AI helps you respond faster and stay organized with smart suggestions⁵ that appear exactly when you need them on your phone

An element screenshot throws an unsupported-operation error

Cause: the WebElement or driver does not implement element screenshots. Fix: use Playwright's locator screenshot, or capture the viewport and crop the target.

Visual regression diffs change between runs

Cause: rendering conditions changed: operating system, browser, settings, hardware, power state, or headless mode. Fix: run comparisons in the same controlled environment and eliminate time-dependent or animated content.

The browser cannot start

Cause: the driver, browser binary, or Playwright-managed browser is missing or incompatible. Fix: install the browser binaries required by the chosen tool, ensure the driver matches the browser, and run the same setup in CI and locally.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The output cannot be opened

Cause: the extension does not match the bytes, or a temporary Selenium file was moved incorrectly. Fix: use a matching extension and image type, copy the Selenium temporary file before quitting the driver, and check the file length before publishing it.

Best Value
Tracfone Moto g Play 2024 Prepaid Phone with a 1-Yr Plan Included
  • Carrier: This phone is locked to Tracfone, which means this device can only be used on the Tracfone wireless network. Activating is easy, just 3 steps.
  • ACTIVATION Promotion: Includes 1500 min, 1500 texts & 1500 MB Data + add more as you need it
  • CAMERA SYSTEM: 50MP Quad Pixel camera. Capture sharper, more vibrant photos day or night with 4x the light sensitivity.
  • PERFORMANCE: Blazing-fast Qualcomm performance. Get the speed you need for great entertainment with a Snapdragon 680 processor and 4GB of RAM.
  • 64GB built-in storage. Get plenty of room for photos, movies, songs, and apps. Made for US
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Performance, reliability, and cost considerations

A local browser gives you control but consumes startup time, memory, browser binaries, and CI maintenance. Reusing a browser process while creating isolated pages can reduce repeated startup overhead, provided pages are closed and state is reset. Limit concurrency to what the host can render reliably; more workers can increase memory pressure and produce timeouts rather than faster captures. Cache only when the URL and rendering inputs are unchanged, because cookies, authorization, viewport, locale, and JavaScript state can alter the result.

For repeatable archives, record the URL, timestamp, viewport, browser engine, operating system, and whether the image is viewport or full-page. For sensitive pages, pass credentials only through the browser's supported authentication mechanisms and protect resulting files as confidential data.

Or skip the browser setup

ScreenshotNeo is a website screenshot API and MCP server. One request returns a PNG, JPEG, WebP, or PDF. It accepts cookie and consent banners as a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each cleanup step can be turned off. Bot checks, CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and the response identifies the result with X-Page-Verdict and X-Billed headers. Its MCP server exposes take_screenshot, get_page_info, and capture_pdf to Claude, Cursor, and other MCP clients.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The API supports full-page capture with lazy images loaded, CSS-selector element capture, dark mode, device presets and custom viewports, retina scale, PDF paper and page controls, custom CSS and JavaScript, clicks, waits, request and resource blocking, headers, cookies, user agents, authorization, timezone, geolocation, transparent backgrounds, resizing, chosen-TTL caching, signed image links, asynchronous jobs with signed webhooks, bulk capture of up to 100 URLs per call, a usage API, and an OpenAPI specification. Parameter names used by other screenshot APIs also work, easing migration.

cURL

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

Python

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

Node.js

const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

See the ScreenshotNeo documentation for request options and response handling. The Free plan includes 1,000 shots per month without a card; paid plans start at $5 for 3,000 shots. Create a free ScreenshotNeo account to start.

Frequently Asked Questions

Can Kotlin save a screenshot without writing a temporary file?

Yes. Playwright returns a screenshot as a Kotlin ByteArray; Selenium can request a base64 representation through OutputType.

Which format should I use for website screenshots?

Use PNG for lossless UI text, JPEG when a smaller photographic file is sufficient, and WebP when your delivery pipeline supports it. The browser libraries and ScreenshotNeo can produce formats according to their documented options.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Why do two screenshots of the same URL differ?

Browser rendering depends on environment and page state. Keep the operating system, browser version, settings, viewport, headless mode, data, and timing consistent, and control animations and changing content.

Quick Recap

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.