当前位置: 动力学知识库 > 问答 > 编程问答 >

selenium - Solution to capture an image using webdriver. Does any one has better solution for this?

问题描述:

I want to share code to capture the screen shot of all tag in selenium webdriver

  1. get all <img> tag in list

    List<WebElement> image = driver.findElements(By.tagName("img"));

    int i=1;

  2. Use this:

    for(WebElement allImages : image){

    //Download image

    File screen=((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);

    int width=allImages.getSize().getWidth();

    int height=allImages.getSize().getHeight();

    BufferedImage img=ImageIO.read(screen);

    BufferedImage dest=img.getSubimage(allImages.getLocation().getX(), allImages.getLocation().getY(), width, height);

    ImageIO.write(dest, "png", screen);

    File file=new File("/Users/h-disk/Desktop/folder-name/abc"+i+".png");

Using this code you can capture all <img>s

网友答案:

You can use frameworks like Gallio or RobotFramework to improve this process

分享给朋友:
您可能感兴趣的文章:
随机阅读: