Interface TakesScreenshot

  • All Known Subinterfaces:
    WebElement

    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:
    OutputType
    • Method Detail

      • 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.
        java.lang.UnsupportedOperationException - if the underlying implementation does not support screenshot capturing.