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.