* For JAVA Project add jars for selenium.
* For Maven Project, add Dependency for selenium
* For Maven Project, add Dependency for selenium
import java.io.File; import org.apache.commons.io.FileUtils; import org.openqa.selenium.OutputType; import org.openqa.selenium.TakesScreenshot; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; public class captureScreenshot { public WebDriver drv; public void screenshot(WebDriver drv, String fileName) throws Exception { File screenshot = ((TakesScreenshot)drv).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(screenshot, new File(fileName)); } public void executeScript() throws Exception{ drv=new FirefoxDriver(); drv.manage().window().maximize(); drv.navigate().to("https://www.google.com/"); screenshot(drv, "D:\\google.png"); drv.close(); } public static void main(String[] args) { captureScreenshot c1=new captureScreenshot(); try { c1.executeScript(); } catch (Exception e) { e.printStackTrace(); } } }