activities
latest
false
UiPath logo, featuring letters U and I in white

UI Automation Activities

Last updated Dec 20, 2024

TakeScreenshot

Takes a screenshot of a specified UI element or application and saves it to a file.

This API must be added after Open or Attach.

Definition

Namespace: UiPath.UIAutomationNext.API.Models

Assembly: UiPath.UIAutomationNext.API.Models (in UiPath.UIAutomationNext.API.Models dll)

Overloads

OverloadDescription
TakeScreenshot(IElementDescriptor, TakeScreenshotOptions)Takes a screenshot of a specified UI element or application and saves it to a file, identified by a descriptor of an element from Object Repository.
TakeScreenshot(IElementDescriptor, String)Takes a screenshot of a specified UI element or application and saves it to a file, identified by a descriptor of an element from Object Repository, while specifying the file name.
TakeScreenshot(String, TakeScreenshotOptions)Takes a screenshot of a specified UI element or application and saves it to a file, identified by a string from Object Repository, along with other configurations.
TakeScreenshot(String, String)Takes a screenshot of a specified UI element or application and saves it to a file, identified by a string from Object Repository, along with other configurations.
TakeScreenshot(RuntimeTarget, TakeScreenshotOptions)Takes a screenshot of a specified UI element or application and saves it to a file, identified by a runtime instance of an Object Repository element, along with other configurations.
TakeScreenshot(TargetAnchorableModel, TakeScreenshotOptions)Takes a screenshot of a specified UI element or application and saves it to a file, identified by the TargetAnchorableModel object, along with other configurations.
TakeScreenshot(TargetAnchorableModel, String)Takes a screenshot of a specified UI element or application and saves it to a file, identified by the TargetAnchorableModel object, while specifying the file name.

TakeScreenshot(IElementDescriptor, TakeScreenshotOptions)

Takes a screenshot of a specified UI element or application and saves it to a file, identified by a descriptor of an element from Object Repository.

TakeScreenhot(
    IElementDescriptor elementDescriptor,
    TakeScreenshotOptions takeScreenshotOptions)TakeScreenhot(
    IElementDescriptor elementDescriptor,
    TakeScreenshotOptions takeScreenshotOptions)
elementDescriptor IElementDescriptor
The element descriptor to take the screenshot from. Leave null to take a screenshot of the entire desktop.
takeScreenshotOptions TakeScreenshotOptions
Additional options to customize the screenshot. You can choose to customize:
  • TargetOptions:
    • Timeout - Specifies the amount of time (in seconds) to wait for the API to run before the SelectorNotFoundException error is thrown. The default value is 30 seconds.
    • DelayAfter - Delay time (in seconds) after executing the API. The default amount of time is 0.3 seconds (300 milliseconds).
    • DelayBefore - Delay time (in seconds) before the API begins performing any operations. The default amount of time is 0.2 seconds (200 milliseconds).
  • FileName - The name of the file you want to save.

TakeScreenshot(IElementDescriptor, String)

Takes a screenshot of a specified UI element or application and saves it to a file, identified by a descriptor of an element from Object Repository, while specifying the file name.

TakeScreenhot(
    IElementDescriptor elementDescriptor,
    string fileName)TakeScreenhot(
    IElementDescriptor elementDescriptor,
    string fileName)
elementDescriptor IElementDescriptor
The element descriptor to take the screenshot from. Leave null to take a screenshot of the entire desktop.
fileName String
The name of the file you want to save.

TakeScreenshot(String, TakeScreenshotOptions)

Takes a screenshot of a specified UI element or application and saves it to a file, identified by a string from Object Repository, along with other configurations.

TakeScreenhot(
    string target,
    TakeScreenshotOptions takeScreenshotOptions)TakeScreenhot(
    string target,
    TakeScreenshotOptions takeScreenshotOptions)
target String
The target to take a screenshot from, identified by a string from Object Repository. Leave null to take a screenshot of the entire desktop.
takeScreenshotOptions TakeScreenshotOptions
Additional options to customize the screenshot. You can choose to customize:
  • TargetOptions:
    • Timeout - Specifies the amount of time (in seconds) to wait for the API to run before the SelectorNotFoundException error is thrown. The default value is 30 seconds.
    • DelayAfter - Delay time (in seconds) after executing the API. The default amount of time is 0.3 seconds (300 milliseconds).
    • DelayBefore - Delay time (in seconds) before the API begins performing any operations. The default amount of time is 0.2 seconds (200 milliseconds).
  • FileName - The name of the file you want to save.

TakeScreenshot(String, String)

Takes a screenshot of a specified UI element or application and saves it to a file, identified by a string from Object Repository, along with other configurations.

TakeScreenhot(
    string target,
    string fileName)TakeScreenhot(
    string target,
    string fileName)
target String
The target to take a screenshot from, identified by a string from Object Repository. Leave null to take a screenshot of the entire desktop.
fileName String
The name of the file you want to save.

TakeScreenshot(RuntimeTarget, TakeScreenshotOptions)

Takes a screenshot of a specified UI element or application and saves it to a file, identified by a runtime instance of an Object Repository element, along with other configurations.

TakeScreenhot(
    RuntimeTarget target,
    TakeScreenshotOptions takeScreenshotOptions)TakeScreenhot(
    RuntimeTarget target,
    TakeScreenshotOptions takeScreenshotOptions)
target RuntimeTarget
The target to take a screenshot from, identified by a runtime instance of an Object Repository element. Leave null to take a screenshot of the entire desktop.
takeScreenshotOptions TakeScreenshotOptions
Additional options to customize the screenshot. You can choose to customize:
  • TargetOptions:
    • Timeout - Specifies the amount of time (in seconds) to wait for the API to run before the SelectorNotFoundException error is thrown. The default value is 30 seconds.
    • DelayAfter - Delay time (in seconds) after executing the API. The default amount of time is 0.3 seconds (300 milliseconds).
    • DelayBefore - Delay time (in seconds) before the API begins performing any operations. The default amount of time is 0.2 seconds (200 milliseconds).
  • FileName - The name of the file you want to save.

TakeScreenshot(TargetAnchorableModel, TakeScreenshotOptions)

Takes a screenshot of a specified UI element or application and saves it to a file, identified by the TargetAnchorableModel object, along with other configurations.
TakeScreenhot(
    TargetAnchorableModel target,
    TakeScreenshotOptions takeScreenshotOptions)TakeScreenhot(
    TargetAnchorableModel target,
    TakeScreenshotOptions takeScreenshotOptions)
target TargetAnchorableModel
The target to take a screenshot from, identified by the TargetAnchorableModel object. Leave null to take a screenshot of the entire desktop.
takeScreenshotOptions TakeScreenshotOptions
Additional options to customize the screenshot. You can choose to customize:
  • TargetOptions:
    • Timeout - Specifies the amount of time (in seconds) to wait for the API to run before the SelectorNotFoundException error is thrown. The default value is 30 seconds.
    • DelayAfter - Delay time (in seconds) after executing the API. The default amount of time is 0.3 seconds (300 milliseconds).
    • DelayBefore - Delay time (in seconds) before the API begins performing any operations. The default amount of time is 0.2 seconds (200 milliseconds).
  • FileName - The name of the file you want to save.

TakeScreenshot(TargetAnchorableModel, String)

Takes a screenshot of a specified UI element or application and saves it to a file, identified by the TargetAnchorableModel object, while specifying the file name.
TakeScreenhot(
    TargetAnchorableModel target, 
    string fileName)TakeScreenhot(
    TargetAnchorableModel target, 
    string fileName)
target TargetAnchorableModel
The target to take a screenshot from, identified by the TargetAnchorableModel object. Leave null to take a screenshot of the entire desktop.
fileName String
The name of the file you want to save.

Code example

Here is a brief walkthrough of a sample code implementation.

This line of code sets up the file path where the screenshot is saved.

var filePath = "C:\\samplefile.jpg";var filePath = "C:\\samplefile.jpg";

This command attaches to a screen from an already opened application.

var sampleApp = uiAutomation.Attach(Descriptors.NewApplication.NewScreen);var sampleApp = uiAutomation.Attach(Descriptors.NewApplication.NewScreen);
The TakeScreenshot API gets invoked here, capturing the screenshot of the newly specified element on your screen and subsequently saving it to the defined file path.
sampleApp.TakeScreenshot(Descriptors.NewApplication.NewScreen.NewElement, filePath);sampleApp.TakeScreenshot(Descriptors.NewApplication.NewScreen.NewElement, filePath);
Checks whether the screenshot file exists at the given filePath.
var fileExists = system.FileExists(filePath);var fileExists = system.FileExists(filePath);
Finally, the statement verifies that the screenshot file has been saved successfully to the target filePath.
testing.VerifyAreEqual(fileExists, true);testing.VerifyAreEqual(fileExists, true);

Adding options

You can add options in your code in two ways.

One way to add options is to use the right overload. To do this, press Ctrl + Space, and IntelliSense appears, enabling you to browse and select your preferred overload. You might decide to select the overload where you have the parameters set up in advance. Optional parameters are indicated within by brackets.
If you want to initialize a single setting like windowResize, you can use this syntax:
var sampleApp = uiAutomation.Attach(Descriptors.NewApplication.NewScreen, windowResize: NWindowResize.Restore);var sampleApp = uiAutomation.Attach(Descriptors.NewApplication.NewScreen, windowResize: NWindowResize.Restore);
Another way to add options is to use a common option overload, such as Attach, and pair it with the Options class. This offers a bit more flexibility in customizing your parameters.

Was this page helpful?

Get The Help You Need
Learning RPA - Automation Courses
UiPath Community Forum
Uipath Logo White
Trust and Security
© 2005-2024 UiPath. All rights reserved.