0

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

4

1 回答 1

1

您可以使用 Gallio 或 RobotFramework 等框架来改进此过程

于 2013-07-05T13:53:13.623 回答