How can I take a screenshot with Selenium WebDriver? (Java)

How can I take a screenshot with Selenium WebDriver? (Java)

You can save screenshots using the TakeScreenshot driver. These screenshots can be taken with three output types: byte array, Base64 or File.

byte[] screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);

You need to import org.openqa.selenium.TakesScreenshot to use the TakeScreenshot driver and org.openqa.selenium.OutputType to save the screenshot.


With MaxTAF you can immediately see the screenshot after the test is run if you use the save screenshot code seen in the script for this example.

mxService.saveScreenshot(screenshot);

See Working Example

Leave a reply

Your email address will not be published. Required fields are marked*

CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.