Java 在selenium中使用safari驱动程序进行图像定位

Java 在selenium中使用safari驱动程序进行图像定位,java,selenium,Java,Selenium,我正在尝试对网页进行屏幕截图,然后检索图像的大小和位置,最后将图像保存到文件中 片段: this.driver.navigate().to(xxx); final byte[] arrScreen = ((TakesScreenshot) this.driver).getScreenshotAs(OutputType.BYTES); final BufferedImage imageScreen = ImageIO.read(new ByteArrayInputStream(arrScreen

我正在尝试对网页进行屏幕截图,然后检索图像的大小和位置,最后将图像保存到文件中

片段:

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操作系统(ChromeDriver和SafariDriver都失败)则无法工作(坐标错误)

知道为什么吗

编辑:

Windows和Mac os中的
TakesScreenshot
有什么区别吗?

我替换了这个:

final BufferedImage imgCap = imageScreen.getSubimage(capLocation.x, capLocation.y,
        capDimension.width, capDimension.height);
有了这个,它工作得很好:

final BufferedImage imgCap = imageScreen.getSubimage(capLocation.x * 2, capLocation.y * 2,
        capDimension.width * 2, capDimension.height * 2);
但我还是不知道为什么,知道吗?

我替换了这个:

final BufferedImage imgCap = imageScreen.getSubimage(capLocation.x, capLocation.y,
        capDimension.width, capDimension.height);
有了这个,它工作得很好:

final BufferedImage imgCap = imageScreen.getSubimage(capLocation.x * 2, capLocation.y * 2,
        capDimension.width * 2, capDimension.height * 2);
但我还是不知道为什么,知道吗