UiPath Documentation
activities
latest
false
用户界面自动化活动
重要 :
请注意,此内容已使用机器翻译进行了部分本地化。 新发布内容的本地化可能需要 1-2 周的时间才能完成。

截取屏幕截图

截取指定用户界面元素或应用程序的屏幕截图,并将其保存为文件。

必须在“打开”“附加”之后添加此 API。

定义

命名空间:UiPath.UIAutomationNext.API.Models

程序集:UiPath.UIAutomationNext.API.Models(位于 UiPath.UIAutomationNext.API.Models dll 中)

重载

重载描述
TakeScreenshot(IElementDescriptor, TakeScreenshotOptions)截取指定用户界面元素或应用程序的屏幕截图,并将其保存到文件中,该文件由对象存储库中的元素描述符标识。
TakeScreenshot(IElementDescriptor, String)截取指定用户界面元素或应用程序的屏幕截图,并将其保存到文件中,该文件由对象存储库中元素的描述符标识,同时指定文件名。
TakeScreenshot(String, TakeScreenshotOptions)截取指定用户界面元素或应用程序的屏幕截图,并将其保存到一个文件中,该文件由对象存储库中的字符串以及其他配置一起标识。
TakeScreenshot(String, String)截取指定用户界面元素或应用程序的屏幕截图,并将其保存到一个文件中,该文件由对象存储库中的字符串以及其他配置一起标识。
TakeScreenshot(RuntimeTarget, TakeScreenshotOptions)截取指定用户界面元素或应用程序的屏幕截图,并将其保存到文件中,该文件由对象存储库元素的运行时实例及其他配置标识。
TakeScreenshot(TargetAnchorableModel, TakeScreenshotOptions)截取指定用户界面元素或应用程序的屏幕截图,并将其与其他配置一起保存到由TargetAnchorableModel对象标识的文件中。
TakeScreenshot(TargetAnchorableModel, String)截取指定用户界面元素或应用程序的屏幕截图,并将其保存到由TargetAnchorableModel对象标识的文件中,同时指定文件名。

TakeScreenshot(IElementDescriptor, TakeScreenshotOptions)

截取指定用户界面元素或应用程序的屏幕截图,并将其保存到文件中,该文件由对象存储库中的元素描述符标识。

TakeScreenhot(
    IElementDescriptor elementDescriptor,
    TakeScreenshotOptions takeScreenshotOptions)
TakeScreenhot(
    IElementDescriptor elementDescriptor,
    TakeScreenshotOptions takeScreenshotOptions)

elementDescriptor IElementDescriptor :要从中截取屏幕截图的元素描述符。离开null可截取整个桌面的屏幕截图。

takeScreenshotOptions TakeScreenshotOptions :用于自定义屏幕截图的其他选项。您可以选择自定义以下项目:

* `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.
* `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)

截取指定用户界面元素或应用程序的屏幕截图,并将其保存到文件中,该文件由对象存储库中元素的描述符标识,同时指定文件名。

TakeScreenhot(
    IElementDescriptor elementDescriptor,
    string fileName)
TakeScreenhot(
    IElementDescriptor elementDescriptor,
    string fileName)

elementDescriptor IElementDescriptor :要从中截取屏幕截图的元素描述符。离开null可截取整个桌面的屏幕截图。

fileName String :要保存的文件的名称。

TakeScreenshot(String, TakeScreenshotOptions)

截取指定用户界面元素或应用程序的屏幕截图,并将其保存到一个文件中,该文件由对象存储库中的字符串以及其他配置一起标识。

TakeScreenhot(
    string target,
    TakeScreenshotOptions takeScreenshotOptions)
TakeScreenhot(
    string target,
    TakeScreenshotOptions takeScreenshotOptions)

target String :要从中截取屏幕截图的目标,由对象存储库中的字符串标识。离开null可截取整个桌面的屏幕截图。

takeScreenshotOptions TakeScreenshotOptions :用于自定义屏幕截图的其他选项。您可以选择自定义以下项目:

* `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.
* `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)

截取指定用户界面元素或应用程序的屏幕截图,并将其保存到一个文件中,该文件由对象存储库中的字符串以及其他配置一起标识。

TakeScreenhot(
    string target,
    string fileName)
TakeScreenhot(
    string target,
    string fileName)

target String :要从中截取屏幕截图的目标,由对象存储库中的字符串标识。离开null可截取整个桌面的屏幕截图。

fileName String :要保存的文件的名称。

TakeScreenshot(RuntimeTarget, TakeScreenshotOptions)

截取指定用户界面元素或应用程序的屏幕截图,并将其保存到文件中,该文件由对象存储库元素的运行时实例及其他配置标识。

TakeScreenhot(
    RuntimeTarget target,
    TakeScreenshotOptions takeScreenshotOptions)
TakeScreenhot(
    RuntimeTarget target,
    TakeScreenshotOptions takeScreenshotOptions)

target RuntimeTarget :截取屏幕截图的目标,由对象存储库元素的运行时实例标识。离开null可截取整个桌面的屏幕截图。

takeScreenshotOptions TakeScreenshotOptions :用于自定义屏幕截图的其他选项。您可以选择自定义以下项目:

* `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.
* `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)

截取指定用户界面元素或应用程序的屏幕截图,并将其与其他配置一起保存到由TargetAnchorableModel对象标识的文件中。

TakeScreenhot(
    TargetAnchorableModel target,
    TakeScreenshotOptions takeScreenshotOptions)
TakeScreenhot(
    TargetAnchorableModel target,
    TakeScreenshotOptions takeScreenshotOptions)

target TargetAnchorableModel :要从中截取屏幕截图的目标,由TargetAnchorableModel对象标识。离开null可截取整个桌面的屏幕截图。

takeScreenshotOptions TakeScreenshotOptions :用于自定义屏幕截图的其他选项。您可以选择自定义以下项目:

* `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.
* `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)

截取指定用户界面元素或应用程序的屏幕截图,并将其保存到由TargetAnchorableModel对象标识的文件中,同时指定文件名。

TakeScreenhot(
    TargetAnchorableModel target, 
    string fileName)
TakeScreenhot(
    TargetAnchorableModel target, 
    string fileName)

target TargetAnchorableModel :要从中截取屏幕截图的目标,由TargetAnchorableModel对象标识。离开null可截取整个桌面的屏幕截图。

fileName String :要保存的文件的名称。

代码示例

以下是示例代码实现的简要演示。

此代码行用于设置保存屏幕截图的文件路径。

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

此命令会附加到已打开的应用程序中的屏幕。

var sampleApp = uiAutomation.Attach(Descriptors.NewApplication.NewScreen);
var sampleApp = uiAutomation.Attach(Descriptors.NewApplication.NewScreen);

TakeScreenshot API 在此处被调用,捕获屏幕上新指定元素的屏幕截图,然后将其保存到定义的文件路径。

sampleApp.TakeScreenshot(Descriptors.NewApplication.NewScreen.NewElement, filePath);
sampleApp.TakeScreenshot(Descriptors.NewApplication.NewScreen.NewElement, filePath);

检查给定的 filePath 中是否存在屏幕截图文件。

var fileExists = system.FileExists(filePath);
var fileExists = system.FileExists(filePath);

最后,该语句验证屏幕截图文件是否已成功保存到目标 filePath 中。

testing.VerifyAreEqual(fileExists, true);
testing.VerifyAreEqual(fileExists, true);

添加选项

您可以通过两种方式在代码中添加选项。

添加选项的一种方法是使用合适的重载。为此,请按 Ctrl + Space,系统便会显示 IntelliSense,使您能够浏览并选择所需的重载。您可能决定选择预先设置了参数的重载。可选参数用括号表示。

如果要初始化 windowResize 等单个设置,可以使用以下语法:

var sampleApp = uiAutomation.Attach(Descriptors.NewApplication.NewScreen, windowResize: NWindowResize.Restore);
var sampleApp = uiAutomation.Attach(Descriptors.NewApplication.NewScreen, windowResize: NWindowResize.Restore);

添加选项的另一种方法是使用常见的选项重载,例如 Attach,并将其与 Options 类配对。这为自定义参数提供了更大的灵活性。

此页面有帮助吗?

连接

需要帮助? 支持

想要了解详细内容? UiPath Academy

有问题? UiPath 论坛

保持更新