简体   繁体   English

如何在Android上拍摄WebElement的图片?

[英]How to take a picture of a WebElement on Android?

I want to be able to take pictures of elements on Android, for example on a page with 4 canvases I want to get a screen grab of only the third canvas. 我希望能够在Android上拍摄元素的图片,例如,在具有4个画布的页面上,我只希望获得第三个画布的屏幕抓图。 I will then do something on the page and use sikuli to make sure the canvas hasn't changed. 然后,我将在页面上执行某些操作,并使用sikuli确保画布未更改。 I can do this on the desktop with the following code: 我可以使用以下代码在桌面上执行此操作:

public void shootWebElement(WebElement element, AndroidDriver driver,String fileName) throws IOException  {

    File screen = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
    Point p = element.getLocation();
    int width = element.getSize().getWidth();
    int height = element.getSize().getHeight();

    BufferedImage img = ImageIO.read(screen);
    BufferedImage dest = img.getSubimage(p.getX(), p.getY(), width,   
                         height);

    ImageIO.write(dest, "png", screen);
    File f = new File(fileName);
    FileUtils.copyFile(screen, f);
}

This code runs on Android but the picture i get back isn't of the element, it's a partial picture of the entire view (this picture will be the same for any element I use as a parameter). 这段代码在Android上运行,但是我得到的图片不是元素的,而是整个视图的局部图片(对于用作参数的任何元素,此图片都是相同的)。

Does anyone know a way around this? 有谁知道解决这个问题的方法吗?

使用selendroid,不推荐使用AndroidDriver,并且不再对其进行维护。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM