Guest User

Untitled

a guest
Feb 23rd, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. driver.get("http://www.google.com");
  2. WebElement ele = driver.findElement(By.id("hplogo"));
  3.  
  4. // Get entire page screenshot
  5. File screenshot = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
  6. BufferedImage fullImg = ImageIO.read(screenshot);
  7.  
  8. // Get the location of element on the page
  9. Point point = ele.getLocation();
  10.  
  11. // Get width and height of the element
  12. int eleWidth = ele.getSize().getWidth();
  13. int eleHeight = ele.getSize().getHeight();
  14.  
  15. // Crop the entire page screenshot to get only element screenshot
  16. BufferedImage eleScreenshot= fullImg.getSubimage(point.getX(), point.getY(),
  17. eleWidth, eleHeight);
  18. ImageIO.write(eleScreenshot, "png", screenshot);
  19.  
  20. // Copy the element screenshot to disk
  21. File screenshotLocation = new File("C:\images\GoogleLogo_screenshot.png");
  22. FileUtils.copyFile(screenshot, screenshotLocation);
Add Comment
Please, Sign In to add comment