我试图使用Selenium和Java截取视频截图。当我使用标题Chrome时它工作正常,但当我想让它无头时,#java; java.awt.image.RasterFormatException:(y + height)超出Raster"投入
getSubimage(point.getX(), point.getY(), eleWidth, eleHeight);
以下是代码:
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--headless");
chromeOptions.addArguments("--start-maximized");
WebDriver driver = new ChromeDriver(chromeOptions);
// Get URL and find image
driver.get("https://www.webcamtaxi.com/en/netherlands/north-holland/purmerend-traffic-cam.html");
Thread.sleep(5000);
while (true) {
WebElement ele = driver.findElement(By.id("insideCam"));
// Get entire page screenshot
File screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
BufferedImage fullImg = ImageIO.read(screenshot);
// Get the location of element on the page
Point point = ele.getLocation();
// Get width and height of the element
int eleWidth = ele.getSize().getWidth();
int eleHeight = ele.getSize().getHeight();
// Crop the entire page screenshot to get only element screenshot
BufferedImage eleScreenshot = fullImg.getSubimage(point.getX(), point.getY(), eleWidth, eleHeight);
ImageIO.write(eleScreenshot, "png", screenshot);
}
有人知道如何解决这个问题吗?