/*
Dependencies:
https://mvnrepository.com/
https://mvnrepository.com/artifact/commons-io/commons-io/2.11.0
https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java/4.1.2
*/
//Taking screenshot
class Main {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://www.amazon.com/");
WebElement element = driver.findElement(By.xpath("//h2[text()='New arrivals in Toys']/parent::div/parent::div"));
//Take screenshot and save it as File format
File f = element.getScreenshotAs(OutputType.FILE);
//Copying the pysical copy of hte screenshot to desired location
FileUtils.copyFile(f, new File("screenshots.png"));
}
}