1
我正在尝试制作网页的屏幕截图,然后检索图像的大小和位置并最终将图像保存到文件中。在硒中使用Safari浏览器驱动程序的图像位置
段:
this.driver.navigate().to(xxx);
final byte[] arrScreen = ((TakesScreenshot) this.driver).getScreenshotAs(OutputType.BYTES);
final BufferedImage imageScreen = ImageIO.read(new ByteArrayInputStream(arrScreen));
final WebElement cap = this.driver.findElement(By.id("myImageId"));
final Dimension capDimension = cap.getSize();
final Point capLocation = cap.getLocation();
final BufferedImage imgCap = imageScreen.getSubimage(capLocation.x, capLocation.y,
capDimension.width, capDimension.height);
final File file = new File(".../capture.png");
final FileOutputStream os = new FileOutputStream(file);
ImageIO.write(imgCap, "png", os);
使用Windows操作系统(ChromeDriver),但它不能正常工作使用Mac OS(ChromeDriver和SafariDriver都失败)(坐标是错误的)这项工作的罚款。
任何想法,为什么?
编辑:
是否有在Windows和Mac OS TakesScreenshot
之间有什么区别?