Skip to content

Instantly share code, notes, and snippets.

@zevnull
Created May 7, 2013 12:36
Show Gist options
  • Save zevnull/5532240 to your computer and use it in GitHub Desktop.
Save zevnull/5532240 to your computer and use it in GitHub Desktop.
Create screenshot for element
BrowserFactory.getExistentWebDriver().switchTo().frame( "outerFrame" );
WebElement ele =
BrowserFactory.getExistentWebDriver().findElement( By.cssSelector( "div#sfahciops > .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 );
//BufferedImage eleScreenshot = fullImg.getSubimage( 372, 495, 700, 197 );
ImageIO.write( eleScreenshot, "png", screenshot );
FileUtils.copyFile( screenshot, new File( "c:\\elementScreenshot2.png" ) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment