Styrow.dev
Question 53 of 82

How to capture screenshot in selenium webdriver?

Question

How to capture screenshot in selenium webdriver?

Answer

Below code can be used to capture screenshot

public static void captureScreenMethod() throws Exception{

System.setProperty(""webdriver.chrome.driver"",""D://Selenium //Drivers//chromedriver.exe"");

WebDriver driver = new ChromeDriver();

driver.manage().window().maximize();

driver.get(""https://www.codeGreen.com"");

File screenshotFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);

FileUtils.copyFile(screenshotFile, new File(""D:\SoftwareTestingMaterial.png""));

driver.close();

driver.quit();

}


šŸ“² Practice Offline on Mobile: Download the free QA Automation & SDET Prep app on Google Play & App Store.