简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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