Skip to main content

WebDriverScreenshotHandler

Captures page screenshots through Selenium WebDriver, as a whole page or a single element.

Notes

Set as the screenshotHandler of a WebDriverFetcher, this takes a screenshot of every page the browser renders. Without a cssSelector it captures what the browser shows; with one, it captures the full page and crops to the matching element — Selenium has no native element capture, so the cropping happens in the crawler.

Screenshots go to a directory, to a document field, or both, and the same options are documented once in ScreenshotHandlerConfig. Writing images into a field means the encoded image travels to your committer, which is rarely what you want: keep the file on disk and index its path instead.

The Playwright equivalent is PlaywrightScreenshotHandler, which captures elements natively.

Examples

fetchers:
- class: WebDriverFetcher
browser: CHROME
screenshotHandler:
targets:
- DIRECTORY
targetDir: ./screenshots

Usage

Full configuration skeleton, with every option and its default
cssSelector: string
imageFormat: string
targetDir: string
targetDirField: string
targetDirStructure: URL2PATH
targetMetaField: string
targets:
- METADATA

Properties

PropertyTypeRequiredDefault
cssSelectorstringNo-
imageFormatstringNo-
targetDirstringNo-
targetDirFieldstringNo-
targetDirStructureenumNo-
targetMetaFieldstringNo-
targetsenum[]No-

Property Details

cssSelector

Capture only the element matching this CSS selector. The page is captured in full and then cropped to it. Leave blank for the whole page.

imageFormat

Image format to write (png by default).

targetDir

Directory screenshots are written to. Default is ./screenshots.

targetDirField

Document field that receives the written file's path. Default is document.screenshot-path.

targetDirStructure

Subdirectory layout under targetDir: DATETIME (default), DATE, or URL2PATH.

Allowed Values

  • URL2PATH
  • DATE
  • DATETIME

targetMetaField

Document field that receives the Base64-encoded image when targets includes METADATA. Default is document.screenshot.

targets

Where the screenshot is stored: DIRECTORY (default), METADATA, or both.