34# How to capture screenshots or multiple screenshots in Selenium

Опубликовано: 14 Апрель 2026
на канале: Knowledge Share
4,018
80

In this session you will learn how to capture Screenshot or multiple Screenshots in Selenium which will help you to be more hands on for framework design. ( Please refer Program code copied at the end )

Github link for all the programs and techniques on Framework design pre-requisites

https://github.com/knowledgeshare-tec...

Please join Facebook Group from below link
  / 4754296501308288  

GitHub Repository link for basic Selenium programs for practise
https://github.com/knowledgeshare-tec...

Please check below Playlist for your easy Learning

Step-by-Step Selenium Learning Playlist
   • Selenium  

Module-wise Learning Playlist for Selenium

Selenium Module - 1 Playlist
   • Selenium - Module_1  

Selenium Module - 2 Playlist
   • Selenium - Module_2  

Selenium Module - 3 Playlist
   • Selenium - Module_3  

Selenium Module - 4 Playlist
   • Selenium - Module_4  

Selenium Module - 5 Playlist
   • Selenium - Module_5  

Selenium Module - 6 Playlist
   • Selenium - Module_6  

Selenium Module - 7 Playlist
   • Selenium - Module_7  

Core Java Basic Concepts Playlist
   • Core Java  

OOPS Concepts Playlist
   • OOPS Concepts in Java  

**************************************
Capture Screenshot Program
**************************************
package framework.prerequisites;

import java.io.File;
import java.io.IOException;

import org.apache.commons.io.FileUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

import io.github.bonigarcia.wdm.WebDriverManager;

public class CaptureScreenshot {

public static void main(String[] args) throws IOException
{

WebDriverManager.firefoxdriver().setup();
WebDriver driver=new FirefoxDriver();
driver.get("http://www.google.com");
driver.manage().window().maximize();
driver.findElement(By.name("q")).sendKeys("Knowledge Share");
File src= ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(src, new File("E:\\Selenium + Java - Youtube\\Screenshots_Captures\\error.png"));

}

}

*******************************************
Capture Multiple Screenshots Program :
*******************************************

package framework.prerequisites;

import java.io.File;
import java.io.IOException;

import org.apache.commons.io.FileUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

import io.github.bonigarcia.wdm.WebDriverManager;

public class CaptureMultipleScreenshot {

public static void main(String[] args) throws IOException
{

WebDriverManager.firefoxdriver().setup();
WebDriver driver=new FirefoxDriver();
driver.get("http://www.google.com");
driver.manage().window().maximize();

CaptureMultipleScreenshot.capture_with_name(driver,"homepage");
driver.findElement(By.name("q")).sendKeys("Knowledge Share");
CaptureMultipleScreenshot.capture_with_name(driver,"texttyped");


}

/*
public static void capture(WebDriver driver) throws IOException { File src=
((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(src, new
File("E:\\Selenium + Java - Youtube\\Screenshots_Captures\\" + System.currentTimeMillis() + "
Screenshot.png")); }
*/

public static void capture_with_name(WebDriver driver,String name) throws IOException
{
File src=((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(src, new File("E:\\Selenium + Java - Youtube\\Screenshots_Captures\\" + name + ".png"));
}

}