Selenium take screenshot of WebElement
public void takeScreenShotOfWebElement(WebDriver driver, By by) throws IOException, InterruptedException
{
File screenShot = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
BufferedImage imageIO = ImageIO.read(screenShot);
WebElement timelineLeftNavAvatar = driver.findElement(by);
Point point = timelineLeftNavAvatar.getLocation();
int height=timelineLeftNavAvatar.getSize().height;
int width=timelineLeftNavAvatar.getSize().width;
BufferedImage subImage = imageIO.getSubimage(point.getX(), point.getY(), height, width);
ImageIO.write(subImage, "png", screenShot);
Thread.sleep(10000);
}
No comments:
Post a Comment