Skip to content
hekra01 edited this page Jan 12, 2017 · 5 revisions

WebDriver support element screenshot command as described in http://www.w3.org/TR/webdriver/#take-element-screenshot

Clarifications:

If the WebDriver cannot capture the entire element bounding rectangle, then it will scroll as much of the element into the current browser viewport as possible and capture the maximum visible area.
Then the bounding rectangle of the element will be captured regardless of the element being hidden/obscured etc...
If the bounding rectangle is 0 height or width an error will be returned.
The expected behavior is to capture what is displayed by the browser to the user, not the UI of the element as a standalone web element, i.e: transparency, overlays, etc... will be captured.

Code sample

This sample uses QtWebDriver's Selenium API, but any augmenter that supports TAKES_ELEMENT_SCREENSHOT does the job.

RemoteWebElement elt = (RemoteWebElement) driver.findElement(By.id("foo"));
elt = (RemoteWebElement) new QtWebkitAugmenter().augment(elt);
File screenshot = ((TakesScreenshot)elt).getScreenshotAs(OutputType.FILE);
Clone this wiki locally