Created
May 7, 2013 12:36
-
-
Save zevnull/5532240 to your computer and use it in GitHub Desktop.
Create screenshot for element
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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