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.