Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I take a screenshot with Selenium WebDriver?

Is it possible to take a screenshot using Selenium WebDriver?

(Note: Not Selenium Remote Control)

like image 514
James Hollingworth Avatar asked Aug 06 '10 08:08

James Hollingworth


People also ask

How many ways we can take screenshot in Selenium?

Three ways to Capture Screenshots with Selenium WebDriver.

Which interface is used to capture the screenshot in Selenium?

Selenium has the TakesScreenshot interface to capture the screenshots during execution of your Selenium script. The TakesScreenshot interface has a method named getScreenshotAs( ) which can capture a screenshot and store it in any location specified by us.

Can Selenium IDE take screenshots?

captureScreenshot (name of screenshot) - Selenium IDE command. captureEntirePageScreenshot takes a screenshot of the whole web page. captureScreenshot takes a screenshot of the visible website part (viewport). This command has the side effect of giving the tab that runs the macro the focus.


1 Answers

Java

Yes, it is possible. The following example is in Java:

WebDriver driver = new FirefoxDriver(); driver.get("http://www.google.com/"); File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); // Now you can do whatever you need to do with it, for example copy somewhere FileUtils.copyFile(scrFile, new File("c:\\tmp\\screenshot.png")); 
like image 94
Sergii Pozharov Avatar answered Oct 19 '22 09:10

Sergii Pozharov