- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
Best way to take screenshot of a web page into Selenium?
We can take screenshots of a web page with Selenium. It is a three way process. Taking a screenshot is one of the most essential steps towards defect and failure analysis.
First, we have to convert the driver object to the TakeScreenshot interface.
Syntax
TakesScreenshot s = (TakesScreenshot)driver;
Next, we have to take the help of the getScreenshotAs method to have an image file and finally copy the file to a location with FileUtils.copyFile method.
Syntax
File src=s.getScreenshotAs(OutputType.FILE); FileUtils.copyFile(src, new File("file path"));
Example
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; import org.openqa.selenium.OutputType; import org.openqa.selenium.TakesScreenshot; import org.apache.commons.io.FileUtils; import java.io.File; public class ScreenshotCapture{ public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.get("https://www.tutorialspoint.com/about/about_careers.htm"); driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); // screenshot capturing File src = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(src, new File("careerpage.png")); driver.quit(); } }
- Related Articles
- Take screenshot of full page with Selenium Python with chromedriver.
- How to take screenshot with Selenium WebDriver?
- What is the best way to take screenshots of tests in Selenium 2?
- Can you take a screenshot of the page using HTML5 Canvas?
- How to take partial screenshot (frame) with Selenium WebDriver?
- How to get the complete screenshot of a page in Selenium with python?
- Save a Web Page with Python Selenium
- How to take partial screenshot with Selenium WebDriver in python?
- Take screenshot of the options in dropdown in selenium c#.
- How to capture the screenshot of a specific element rather than entire page using Selenium Webdriver?
- How to get the screenshot of a particular element in the page in Selenium with python?
- How to scroll a Web Page using coordinates of a WebElement in Selenium WebDriver?
- Selenium Web Test Automation Framework Best Practices.
- How to take screenshot of a div with JavaScript
- How to programmatically take a screenshot in android?

Advertisements