Verify element action with screen shot in selenium 4 - java
public static void verify_element_withScreenShot__(WebElement element,String NameOfElement) throws IOException {
screenshot_Path = AutoTest_PropertiesLoader.get_property("config", "screenshot_Path");
try {
TakesScreenshot screenshot = element;
File src = screenshot.getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(src, new File(screenshot_Path+"/stepVerification/"+NameOfElement+ ".png"));
} catch (Exception e) {
System.out.println("Error occurred while taking screenshot " + e.getMessage());
}
}