Interface TakesScreenshot

All Known Subinterfaces:
WebElement
All Known Implementing Classes:
ChromeDriver, ChromiumDriver, EdgeDriver, FirefoxDriver, InternetExplorerDriver, RemoteWebDriver, RemoteWebElement, SafariDriver

@NullMarked public interface TakesScreenshot
Indicates a driver or an HTML element that can capture a screenshot and store it in different ways.

Example usage:

 File screenshotFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
 String screenshotBase64 = ((TakesScreenshot) element).getScreenshotAs(OutputType.BASE64);
 
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    <X> X
    Capture the screenshot and store it in the specified location.
  • Method Details

    • getScreenshotAs

      <X> X getScreenshotAs(OutputType<X> target) throws WebDriverException
      Capture the screenshot and store it in the specified location.

      For a W3C-conformant WebDriver or WebElement, this behaves as stated in W3C WebDriver specification.

      For a non-W3C-conformant WebDriver, this makes a best effort depending on the browser to return the following in order of preference:

      • Entire page
      • Current window
      • Visible portion of the current frame
      • The screenshot of the entire display containing the browser
      For a non-W3C-conformant WebElement extending TakesScreenshot, this makes a best effort depending on the browser to return the following in order of preference:
      • The entire content of the HTML element
      • The visible portion of the HTML element
      Type Parameters:
      X - Return type for getScreenshotAs.
      Parameters:
      target - target type, @see OutputType
      Returns:
      Object in which is stored information about the screenshot.
      Throws:
      WebDriverException - on failure.
      UnsupportedOperationException - if the underlying implementation does not support screenshot capturing.