---
description: Here is a step-by-step process on how to take a screenshot in selenium. Selenium can automatically take screenshots during execution.
title: How to Take Screenshot in Selenium WebDriver
image: https://www.guru99.com/images/how-to-take-screenshot-in-selenium-webdriver.png
---

 

[Skip to content](#main) 

**⚡ Smart Summary**

Take Screenshot in Selenium WebDriver explains capturing visual evidence for debugging and visual regression, covering TakesScreenshot, full-page, element captures, and AShot.

* 📷 **Why Capture:** Prove failures and document runs.
* 🛠️ **TakesScreenshot:** Cast WebDriver, call getScreenshotAs, save file.
* 🖼️ **Element Capture:** Selenium 4 supports getScreenshotAs on a WebElement.
* 📦 **AShot:** Stitches full pages and compares pixels.
* 🤖 **AI Visual Tests:** Applitools detects diffs while ignoring noise.
* 📊 **Reports:** Embed screenshots in Allure or ExtentReports.

[ Read More ](javascript:void%280%29;) 

![How to Take Screenshot in Selenium WebDriver](https://www.guru99.com/images/how-to-take-screenshot-in-selenium-webdriver.png)

## Screenshot in Selenium

A **Screenshot in Selenium Webdriver** is used for bug analysis. Selenium webdriver can automatically take screenshots during the execution. But if users need to capture a screenshot on their own, they need to use the TakeScreenshot method which notifies the WebDrive to take the screenshot and store it in Selenium.

[](https://www.guru99.com/images/AdvanceSelenium/071514%5F0728%5FPDFEmailsan8.png)

## How to Take Screenshot in Selenium

Here is a step-by-step process on how to capture screenshot in selenium WebDriver

**Step 1)** Convert web driver object to TakeScreenshot

TakesScreenshot scrShot =((TakesScreenshot)webdriver);

**Step 2)** Call getScreenshotAs method to create image file

File SrcFile=scrShot.getScreenshotAs(OutputType.FILE);

**Step 3)** Copy file to Desired Location

Example: In this example we will take screen capture of <https://demo.guru99.com/V4/> & save it as C:/Test.png

**Here is the screenshot code in selenium:**

package Guru99TakeScreenshot; 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; import org.testng.annotations.Test; public class Guru99TakeScreenshot { @Test public void testGuru99TakeScreenShot() throws Exception{ WebDriver driver ; System.setProperty("webdriver.gecko.lkw">driver","C:\\\\geckodriver.exe"); driver \= new FirefoxDriver(); //goto url driver.get("https://demo.guru99.com/V4/"); //Call take screenshot functionthis.takeSnapShot(driver, "c://test.png") ; } /\*\* \* This function will take screenshot \* @param webdriver \* @param fileWithPath \* @throws Exception \*/ public static void takeSnapShot(WebDriver webdriver,String fileWithPath) throws Exception{ //Convert web driver object to TakeScreenshot TakesScreenshot scrShot =((TakesScreenshot)webdriver); //Call getScreenshotAs method to create image fileFile SrcFile=scrShot.getScreenshotAs(OutputType.FILE); //Move image file to new destination File DestFile=new File(fileWithPath); //Copy file at destinationFileUtils.copyFile(SrcFile, DestFile); } } 

**NOTE:** Selenium version 3.9.0 and above does not provide Apache Commons IO JAR. You can simply download them [here](https://commons.apache.org/proper/commons-io/download%5Fio.cgi) and call them in your project

### RELATED ARTICLES

* [Verify Element Present & waitFor Command in Selenium ](https://www.guru99.com/enhancing-selenium-ide-script.html "Verify Element Present & waitFor Command in Selenium")
* [Selenium Framework: Data, Keyword & Hybrid Driven ](https://www.guru99.com/creating-keyword-hybrid-frameworks-with-selenium.html "Selenium Framework: Data, Keyword & Hybrid Driven")
* [FindElement by XPath in Selenium ](https://www.guru99.com/find-element-selenium.html "FindElement by XPath in Selenium")
* [How to Handle Proxy Authentication in Selenium Webdriver ](https://www.guru99.com/selenium-proxy-authentication.html "How to Handle Proxy Authentication in Selenium Webdriver")

## What is Ashot API?

Ashot is a third party utility by Yandex supported by Selenium WebDriver to capture the Screenshots. It takes a screenshot of an individual WebElement as well as a full-page screenshot of a page, which is more significant than screen size.

## How to download and configure Ashot API?

There are two methods to configure Ashot API

1. Using Maven
2. Manually without using any tool

### To configure through Maven:

* Go to <https://mvnrepository.com/artifact/ru.yandex.qatools.ashot/ashot>
* Click on the latest version, for now. It is 1.5.4
* Copy the Dependency code and add to your pom.xml file

[](https://www.guru99.com/images/1/102219%5F1041%5FHowtoTakeSc2.png)

* Save the file, and Maven will add the jar to your build path
* And now you are ready!!!

### To configure manually without any dependency tool

1. Go to <https://mvnrepository.com/artifact/ru.yandex.qatools.ashot/ashot>
2. Click on the latest version, for now. It is 1.5.4
3. Click on the jar, download and save it on your machine

[](https://www.guru99.com/images/1/102219%5F1041%5FHowtoTakeSc3.png)

1. Add the jar file in your build path:
2. In Eclipse, right-click on the project -> go to properties -> Build Path -> Libraries -> Add External jars
3. Select the jar file
4. Apply and Close

## Capture Full Page Screenshot with AShot API

**Step 1)** Create an Ashot object and call takeScreenshot() method if you just want the screenshot for the screen size page.

Screenshot screenshot = new Ashot().takeScreenshot(driver);

But if you want a screenshot of the page bigger then the screen size, call the shootingStrategy() method before calling takeScreenshot() method to set up the policy. Then call a method takeScreenshot() passing the webdriver, for example,

Screenshot screenshot = new AShot().shootingStrategy(ShootingStrategies.viewportPasting(1000)).takeScreenshot(driver);

Here 1000 is scrolled out time in milliseconds, so for taking a screenshot, the program will scroll for each 1000 msec.

**Step 2):** Now, get the image from the screenshot and write it to the file. You can provide the file type as jpg, png, etc.

ImageIO.write(screenshot.getImage(), "jpg", new File(".\\screenshot\\fullimage.jpg"));

Taking a full-page screenshot of a page which is bigger than screen size.

**Example:** Here is the example of capturing a full-page screenshot of <https://demo.guru99.com/test/guru99home/> and save to file “screenshot.jpg.”

Due to using the ShootingStrategy class of Ashot API, we will be able to capture a full image of a page bigger than the screen size.

**Here is the screenshot code in selenium program:**

package Guru99; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; import org.openqa.selenium.By; import org.openqa.selenium.WebElement; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import ru.yandex.qatools.ashot.AShot; import ru.yandex.qatools.ashot.Screenshot; import ru.yandex.qatools.ashot.shooting.ShootingStrategies; public class TestScreenshotUsingAshot { public static void main(String\[\] args) throws IOException { System.setProperty("webdriver.chrome.lkw">driver", "c:\\\\chromedriver.exe"); WebDriver driver \= new ChromeDriver(); driver.get("https://demo.guru99.com/test/guru99home/"); driver.manage().window().maximize(); Screenshot = new AShot().shootingStrategy(ShootingStrategies.viewportPasting(1000)).takeScreenshot(driver); ImageIO.write(screenshot.getImage(), "jpg", new File("c:\\\\ElementScreenshot.jpg")); } } 

## Taking a screenshot of a particular element of the page

**Example:** Here is the example of capturing element screenshot of Guru 99 logo on <https://demo.guru99.com/test/guru99home/> page and save to file “ElementScreenshot.jpg”.

**Here is the screenshot code in selenium:**

package Guru99; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; import org.openqa.selenium.By; import org.openqa.selenium.WebElement; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import ru.yandex.qatools.ashot.AShot; import ru.yandex.qatools.ashot.Screenshot; import ru.yandex.qatools.ashot.shooting.ShootingStrategies; public class TestElementScreenshotUsingAshot { public static void main(String\[\] args) throws IOException { System.setProperty("webdriver.chrome.lkw">driver", "c:\\\\chromedriver.exe"); WebDriver driver \= new ChromeDriver(); driver.get("https://demo.guru99.com/test/guru99home/"); driver.manage().window().maximize(); // Find the element to take a screenshot WebElement element \= driver.findElement(By.xpath ("//\*\[@id=\\"site-name\\"\]/a\[1\]/img")); // Along with driver pass element also in takeScreenshot() method. Screenshot = new AShot().shootingStrategy(ShootingStrategies.viewportPasting(1000)).takeScreenshot(driver,element); ImageIO.write(screenshot.getImage(), "jpg", new File("c:\\\\ElementScreenshot.jpg")); } } 

## Image Comparison using AShot

package Guru99; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import ru.yandex.qatools.ashot.AShot; import ru.yandex.qatools.ashot.Screenshot; import ru.yandex.qatools.ashot.comparison.ImageDiff; import ru.yandex.qatools.ashot.comparison.ImageDiffer; public class TestImageComaprison { public static void main(String\[\] args) throws IOException { System.setProperty("webdriver.chrome.lkw">driver", "C:\\\\chromedriver.exe"); WebDriver driver \= new ChromeDriver(); driver.get("https://demo.guru99.com/test/guru99home/"); // Find the element and take a screenshot WebElement logoElement = driver.findElement(By.xpath("//\*\[@id=\\"site-name\\"\]/a\[1\]/img")); Screenshot logoElementScreenshot = new AShot().takeScreenshot(driver, logoElemnent); // read the image to compareBufferedImage expectedImage = ImageIO.read(new File("C:\\\\Guru99logo.png")); BufferedImage actualImage = logoElementScreenshot.getImage(); // Create ImageDiffer object and call method makeDiff()ImageDiffer imgDiff = new ImageDiffer(); ImageDiff diff = imgDiff.makeDiff(actualImage, expectedImage); if (diff.hasDiff() == true) { System.out.println("Images are same"); } else { System.out.println("Images are different"); } driver.quit(); } } 

## FAQs

⚡ Why capture screenshots?

They document failures and prove intermittent bugs quickly.

🤖 How does AI improve visual testing?

Tools like Applitools compare screenshots intelligently, ignoring dynamic content.

💡 Can AI generate screenshot code?

Yes. AI tools produce TakesScreenshot, AShot, and Selenium 4 snippets.

🖼️ Full-page screenshot in Selenium?

Use AShot or Selenium 4 with Chrome DevTools Page.captureScreenshot.

🧩 TakesScreenshot vs AShot?

TakesScreenshot grabs the viewport. AShot stitches full pages.

🔒 Safe to capture password fields?

It captures what renders. Redact sensitive data before sharing.

📂 Where are screenshots stored?

Save the file returned by getScreenshotAs yourself.

📚 Does Selenium 4 ease element shots?

Yes. Use element.getScreenshotAs(OutputType.FILE) directly.

#### Summarize this post with:

ChatGPT Perplexity Grok Google AI 

**Stay Updated on AI** **Get Weekly AI Skills, Trends, Actionable Advice.** 

##### Sign up for the newsletter

Subscribe for Free 

You have successfully subscribed.  
Please check your inbox. 

![AI-Newsletter]() Chosen by over **350,000+** professionals 

[Scroll to top ](#wrapper)Scroll to top 

× 

Toggle Menu Close 

Search for: 

Search

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://www.guru99.com/#organization","name":"Guru99","sameAs":["https://www.facebook.com/Guru99Official","https://twitter.com/guru99com"],"logo":{"@type":"ImageObject","@id":"https://www.guru99.com/#logo","url":"https://www.guru99.com/images/guru99-logo-v1-150x59.png","contentUrl":"https://www.guru99.com/images/guru99-logo-v1-150x59.png","caption":"Guru99","inLanguage":"en-US"}},{"@type":"WebSite","@id":"https://www.guru99.com/#website","url":"https://www.guru99.com","name":"Guru99","publisher":{"@id":"https://www.guru99.com/#organization"},"inLanguage":"en-US"},{"@type":"ImageObject","@id":"https://www.guru99.com/images/how-to-take-screenshot-in-selenium-webdriver.png","url":"https://www.guru99.com/images/how-to-take-screenshot-in-selenium-webdriver.png","width":"700","height":"250","caption":"How to Take Screenshot in Selenium WebDriver","inLanguage":"en-US"},{"@type":"BreadcrumbList","@id":"https://www.guru99.com/take-screenshot-selenium-webdriver.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":"1","item":{"@id":"https://www.guru99.com","name":"Home"}},{"@type":"ListItem","position":"2","item":{"@id":"https://www.guru99.com/selenium","name":"Selenium"}},{"@type":"ListItem","position":"3","item":{"@id":"https://www.guru99.com/take-screenshot-selenium-webdriver.html","name":"How to Take Screenshot in Selenium WebDriver"}}]},{"@type":"WebPage","@id":"https://www.guru99.com/take-screenshot-selenium-webdriver.html#webpage","url":"https://www.guru99.com/take-screenshot-selenium-webdriver.html","name":"How to Take Screenshot in Selenium WebDriver","dateModified":"2026-06-23T16:16:16+05:30","isPartOf":{"@id":"https://www.guru99.com/#website"},"primaryImageOfPage":{"@id":"https://www.guru99.com/images/how-to-take-screenshot-in-selenium-webdriver.png"},"inLanguage":"en-US","breadcrumb":{"@id":"https://www.guru99.com/take-screenshot-selenium-webdriver.html#breadcrumb"}},{"@type":"Person","@id":"https://www.guru99.com/author/admin","name":"Krishna Rungta","url":"https://www.guru99.com/author/admin","image":{"@type":"ImageObject","@id":"https://www.guru99.com/images/krishna-rungta-v2-120x120.png","url":"https://www.guru99.com/images/krishna-rungta-v2-120x120.png","caption":"Krishna Rungta","inLanguage":"en-US"},"worksFor":{"@id":"https://www.guru99.com/#organization"}},{"articleSection":"Selenium","headline":"How to Take Screenshot in Selenium WebDriver","description":"Here is a step-by-step process on how to take a screenshot in selenium. Selenium can automatically take screenshots during execution.","keywords":"selenium","speakable":{"@type":"SpeakableSpecification","cssSelector":[".entry-title",".summary"]},"@type":"Article","author":{"@id":"https://www.guru99.com/author/admin","name":"Krishna Rungta"},"dateModified":"2026-06-23T16:16:16+05:30","image":{"@id":"https://www.guru99.com/images/how-to-take-screenshot-in-selenium-webdriver.png"},"copyrightYear":"2026","name":"How to Take Screenshot in Selenium WebDriver","subjectOf":[{"@type":"HowTo","name":"How to Take Screenshot in Selenium","description":"Here is a step-by-step process on how to take a screenshot in selenium:","step":[{"@type":"HowToStep","name":"Step 1) Convert web driver object to TakeScreenshot","text":"TakesScreenshot scrShot =((TakesScreenshot)webdriver);","url":"https://www.guru99.com/take-screenshot-selenium-webdriver.html#step1"},{"@type":"HowToStep","name":"Step 2) Call getScreenshotAs method to create image file","text":"File SrcFile=scrShot.getScreenshotAs(OutputType.FILE);","url":"https://www.guru99.com/take-screenshot-selenium-webdriver.html#step2"},{"@type":"HowToStep","name":"Step 3) Copy file to Desired Location","text":"In this example we will take screen capture of http://demo.guru99.com/V4/ &amp; save it as C:/Test.png","url":"https://www.guru99.com/take-screenshot-selenium-webdriver.html#step3"}]},{"@type":"FAQPage","mainEntity":[{"@type":"Question","name":"Why capture screenshots?","acceptedAnswer":{"@type":"Answer","text":"They document failures and prove intermittent bugs quickly."}},{"@type":"Question","name":"How does AI improve visual testing?","acceptedAnswer":{"@type":"Answer","text":"Tools like Applitools compare screenshots intelligently, ignoring dynamic content."}},{"@type":"Question","name":"Can AI generate screenshot code?","acceptedAnswer":{"@type":"Answer","text":"Yes. AI tools produce TakesScreenshot, AShot, and Selenium 4 snippets."}},{"@type":"Question","name":"Full-page screenshot in Selenium?","acceptedAnswer":{"@type":"Answer","text":"Use AShot or Selenium 4 with Chrome DevTools Page.captureScreenshot."}},{"@type":"Question","name":"TakesScreenshot vs AShot?","acceptedAnswer":{"@type":"Answer","text":"TakesScreenshot grabs the viewport. AShot stitches full pages."}},{"@type":"Question","name":"Safe to capture password fields?","acceptedAnswer":{"@type":"Answer","text":"It captures what renders. Redact sensitive data before sharing."}},{"@type":"Question","name":"Where are screenshots stored?","acceptedAnswer":{"@type":"Answer","text":"Save the file returned by getScreenshotAs yourself."}},{"@type":"Question","name":"Does Selenium 4 ease element shots?","acceptedAnswer":{"@type":"Answer","text":"Yes. Use element.getScreenshotAs(OutputType.FILE) directly."}}]}],"@id":"https://www.guru99.com/take-screenshot-selenium-webdriver.html#schema-247093","isPartOf":{"@id":"https://www.guru99.com/take-screenshot-selenium-webdriver.html#webpage"},"publisher":{"@id":"https://www.guru99.com/#organization"},"inLanguage":"en-US","mainEntityOfPage":{"@id":"https://www.guru99.com/take-screenshot-selenium-webdriver.html#webpage"}}]}
```
