I have to capture a screenshot of an image of a particular website. Maybe this is 20% off entire screen, I have used below code, it is capturing the entire screen. Which is
I am using selenium-java-3.141.59 and ChromeDriver 83.0.4103.39, this code below works perfectly for me:
WebDriver driver = new ChromeDriver();
driver.get("https://www.google.com/");
WebElement element = driver.findElement(By.id("hplogo"));
Screenshot screenshotHeader = new AShot().coordsProvider(new WebDriverCoordsProvider()).shootingStrategy(ShootingStrategies.viewportPasting(100)).takeScreenshot(driver, element);
try {
ImageIO.write(screenshotHeader.getImage(),"jpg",new File("C:/TESTSELENIUM/Google.jpg"));
} catch (IOException e) {
e.printStackTrace();
}