Skip to content

get_screenshot

roei sabag edited this page Jul 12, 2020 · 1 revision

Description

Gets an OpenQA.Selenium.Screenshot object representing the image of the page on and saves the screenshot to a file, overwriting the file if it already exists.

Scope

Web, Mobile Web, Mobile Native or any other Web Driver implementation which implements Screenshot.

Properties

Property Description
argument The full path and file name to save the screenshot to. Support formats ['BMP','GIF','JPEG','TIFF','PNG'].
onElement The locator value by which the element will be found.
locator The locator type by which the element will be found.

Command Line Arguments (CLI)

None

W3C Web Driver Protocol

https://www.w3.org/TR/webdriver/#actions

Examples

Example no. 1

Can be tested on

Saves a web driver screenshot as page.png (you can use different format, see below) to the given path (whole page - not including address bar).

Action Rule (JSON)

{
    "action": "GetScreenshot",
    "argument": "GetScreenshot/image.png"
}

Rhino Literal

get screenshot {GetScreenshot/image.png}

CSharp

// option no.1
var actionRule = new ActionRule
{
    Action = PluginsList.GetScreenshot,
    Argument = "GetScreenshot/image.png"
};

// option no.2
var actionRule = new
{
    Action = "GetScreenshot",
    Argument = "GetScreenshot/image.png"
};

Python

action_rule = {
    "action": "GetScreenshot",
    "argument": "GetScreenshot/image.png"
}

Java Script

var actionRule = {
    action: "GetScreenshot",
    argument: "GetScreenshot/image.png"
};

Java

ActionRule actionRule = new ActionRule()
        .setAction("GetScreenshot")
        .setArgument("GetScreenshot/image.png");

Example no. 2

Can be tested on

Saves a web element screenshot as element.png to the given path (you can use different format, see below).

Action Rule (JSON)

{
    "action": "GetScreenshot",
    "argument": "GetScreenshot/image.png",
    "onElement": "//div[@class='jumbotron']"
}

Rhino Literal

get screenshot {GetScreenshot/image.png} on {//div[@class='jumbotron']}

CSharp

// option no.1
var actionRule = new ActionRule
{
    Action = PluginsList.GetScreenshot,
    Argument = "GetScreenshot/image.png",
    OnElement = "//div[@class='jumbotron']"
};

// option no.2
var actionRule = new
{
    Action = "GetScreenshot",
    Argument = "GetScreenshot/image.png",
    OnElement = "//div[@class='jumbotron']"
};

Python

action_rule = {
    "action": "GetScreenshot",
    "argument": "GetScreenshot/image.png",
    "onElement": "//div[@class='jumbotron']"
}

Java Script

var actionRule = {
    "action": "GetScreenshot",
    "argument": "GetScreenshot/image.png",
    "onElement": "//div[@class='jumbotron']"
};

Java

ActionRule actionRule = new ActionRule()
        .setAction("GetScreenshot")
        .setArgument("GetScreenshot/image.png")
        .setOnElement("//div[@class='jumbotron']");

Clone this wiki locally