一、
driver.get("。。。。。");
WebElement ele = driver.findElement(By.id("hplogo"));
File screenshot = ((TakesScreenshot)driver).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);
File screenshotLocation = new File("C:no1.png");
FileUtils.copyFile(screenshot, screenshotLocation);