- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to capture screenshots in Selenium?
We can capture screenshots in Selenium with the help of TakesScreenshot interface. For capturing the screenshot and holding it in a specific location, getScreenshotAs() method is used.
Example
import org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; import java.io.File; import org.apache.commons.io.FileUtils; import org.openqa.selenium.OutputType; import org.openqa.selenium.TakesScreenshot; public class ScreenshotFull{ public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); WebDriver driver = new ChromeDriver(); String url = "https://www.tutorialspoint.com/questions/index.php"; driver.get(url); driver.manage().timeouts().implicitlyWait(12, TimeUnit.SECONDS); // capture screenshot with getScreenshotAs() and store in the //Screenshots folder TakesScreenshot s = (TakesScreenshot)driver; File source = s.getScreenshotAs(OutputType.FILE); FileUtils.copyFile(source, new File("./Screenshots/tutorialpoint.png")); driver.quit(); } }
- Related Articles
- How to capture tooltip in Selenium using getAttribute?
- How to capture tooltip in Selenium using Actions Class?
- How to capture the text from Alert Message in Selenium Webdriver?
- What is the best way to take screenshots of tests in Selenium 2?
- How can I capture network traffic of a specific page using Selenium?
- How to capture SIGINT in Python?
- How to capture the screenshot of a specific element rather than entire page using Selenium Webdriver?
- How to capture null reference exception in C#?
- How to capture Oracle errors in PL/SQL?
- How to capture divide by zero exception in Java?
- How to capture file not found exception in Java?
- How to capture divide by zero exception in C#?
- How to capture file not found exception in C#?
- How to capture out of memory exception in C#?
- Where are iOS simulator screenshots stored?

Advertisements