Skip to content

Instantly share code, notes, and snippets.

@zevnull
Created May 24, 2013 10:35
Show Gist options
  • Save zevnull/5642632 to your computer and use it in GitHub Desktop.
Save zevnull/5642632 to your computer and use it in GitHub Desktop.
Element screenshot
BrowserFactory.getExistentWebDriver().switchTo().frame( "outerFrame" );
WebElement ele =
BrowserFactory.getExistentWebDriver().findElement( By.cssSelector( "canvas.flot-overlay" ) );
File screenshot = ( ( TakesScreenshot ) BrowserFactory.getExistentWebDriver() ).getScreenshotAs( OutputType.FILE );
BufferedImage fullImg = ImageIO.read( screenshot );
Point point = ele.getLocation();
int eleWidth = ele.getSize().getWidth();
int eleHeight = ele.getSize().getHeight();
BufferedImage eleScreenshot = fullImg.getSubimage( point.getX(), point.getY(), eleWidth, eleHeight );
ImageIO.write( eleScreenshot, "png", screenshot );
FileUtils.copyFile( screenshot, new File( "elementScreenshot66.png" ) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment