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
- YAML
- JSON
- XML
fetchers:
- class: WebDriverFetcher
browser: CHROME
screenshotHandler:
targets:
- DIRECTORY
targetDir: ./screenshots
{
"fetchers": [
{
"class": "WebDriverFetcher",
"browser": "CHROME",
"screenshotHandler": {
"targets": [
"DIRECTORY"
],
"targetDir": "./screenshots"
}
}
]
}
<fetchers>
<fetcher class="WebDriverFetcher">
<browser>CHROME</browser>
<screenshotHandler>
<targets>
<target>DIRECTORY</target>
</targets>
<targetDir>./screenshots</targetDir>
</screenshotHandler>
</fetcher>
</fetchers>
Usage
Full configuration skeleton, with every option and its default
- YAML
- JSON
- XML
cssSelector: string
imageFormat: string
targetDir: string
targetDirField: string
targetDirStructure: URL2PATH
targetMetaField: string
targets:
- METADATA
{
"cssSelector": "string",
"imageFormat": "string",
"targetDir": "string",
"targetDirField": "string",
"targetDirStructure": "URL2PATH",
"targetMetaField": "string",
"targets": [
"METADATA"
]
}
<screenshotHandler>
<cssSelector>string</cssSelector>
<imageFormat>string</imageFormat>
<targetDir>string</targetDir>
<targetDirField>string</targetDirField>
<targetDirStructure>URL2PATH</targetDirStructure>
<targetMetaField>string</targetMetaField>
<targets>
<target>METADATA</target>
</targets>
</screenshotHandler>
Properties
| Property | Type | Required | Default |
|---|---|---|---|
cssSelector | string | No | - |
imageFormat | string | No | - |
targetDir | string | No | - |
targetDirField | string | No | - |
targetDirStructure | enum | No | - |
targetMetaField | string | No | - |
targets | enum[] | 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
URL2PATHDATEDATETIME
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.