UiPath Documentation
activities
latest
false
重要 :
请注意,此内容已使用机器翻译进行了部分本地化。 新发布内容的本地化可能需要 1-2 周的时间才能完成。
UiPath logo, featuring letters U and I in white

用户界面自动化活动

上次更新日期 2026年4月28日

打开

打开要在用户界面自动化中使用的桌面应用程序或网页浏览器页面。

通过根据以下格式调用 UIAutomation 服务来使用此 API: uiAutomation.API() 。 例如uiAutomation.Open()

定义

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

程序集:UiPath.UIAutomationNext.API.Contracts(在 UiPath.UIAutomationNext.API.Contracts dll 中)

重载

重载描述
Open(String, TargetAppOptions, String, String)打开要在用户界面自动化中使用的特定桌面应用程序或网页,由对象存储库中的屏幕名称标识。
Open(TargetAppModel, TargetAppOptions)打开要在用户界面自动化中使用的特定桌面应用程序或网页,由 TargetAppModel 对象标识。
Open(String, String, String, NAppOpenMode, NWindowResize, NInteractionMode)打开要在用户界面自动化中使用的特定桌面应用程序或网页,由对象存储库中的屏幕名称以及应用程序或网页的其他自定义项标识。

Open(String, TargetAppOptions, String, String)

打开要在用户界面自动化中使用的特定桌面应用程序或网页,由对象存储库中的屏幕名称标识。

Open(
    string screenName,  
    TargetAppOptions targetAppOptions, 
    [string appName],
    [string appVersion])
Open(
    string screenName,  
    TargetAppOptions targetAppOptions, 
    [string appName],
    [string appVersion])

screeName String :要关注的屏幕的名称,以字符串形式记录在对象存储库中。

targetAppOptions :用于附加到应用程序或网页的其他选项和设置:

* `Timeout Double` - Specify a number
  of seconds for which to wait for the activity to be executed before
  throwing an error. The default value is 30 seconds. When indicating
  a window in a Remote Desktop environment, the Timeout default
  setting is set to 60 seconds.
* `InteractionMode
  NInteractionMode`:
  + `HardwareEvents` - Uses the hardware
    driver to perform the action. This is the slowest API, it
    cannot work in the background, but it is compatible with all
    desktop apps.
  + `Simulate` - Simulates the action using
    accessibility APIs. Recommended in browser automation, Java
    apps, or SAP. More reliable than Hardware Events. Sends all
    text in a single action. Works even if the target
    application is not in focus. Please test if your target
    application UI element supports this.
  + `DebuggerApi` - Performs actions using
    debugger APIs. Works only for Chromium elements. Sends all
    text in one go. Works even if target app is not in focus.
    For more details, check out this [page](https://docs.uipath.com/studio/docs/chromium-api).
  + `WindowMessages` - Sends the mouse and
    keyboard input through Win32 messages. Recommended for
    desktop apps. Usually more reliable than Hardware Events.
    Sends all text in a single action. Works even if target app
    is not in focus. Please test if your target application UI
    element supports this.
  + `Background` - Runs actions in the
    background. Tries to use either Simulate or Chromium API
    where possible, while complex APIs (image, native text)
    run as usual, in the foreground. It is highly recommended to
    use this API with the [Verify Execution](https://docs.uipath.com/activities/other/latest/user-guide/project-settings-ui-automation)
    feature.
* `OpenMode NAppOpenMode` - choose when
  to open the app:
  + `Never` (never open the
    application)
  + `IfNotOpen` (open only if the
    application is closed, this is the default selection, only
    works if `FilePath` or `URL`
    are provided)
  + `Always` (open another instance of the
    application even if one is already open, only works if
    `FilePath` or `URL` are
    provided)
* `WindowResize NWindowResize` - choose
  the size of the window:
  + `None`
  + `Maximize`
  + `Restore`
  + `Minimize`
* `UserDataFolderMode
  BrowserUserDataFolderMode` - The
  `UserDataFolderMode` you want to set. It is used
  to start the browser with a specific user data folder.
  + `Automatic` - Picture In Picture mode
    uses a different folder than the default mode, automatically
    generated if `UserDataFolderPath` is not
    set.
  + `DefaultFolder` - Uses the default
    browser folder, no matter if it runs in the main or PIP
    session.
  + `CustomFolder` - Uses the folder
    specified in `UserDataFolderPath` or an auto
    generated path if `UserDataFolderPath` is not
    set.
* `UserDataFolderPath String` - The
  user data folder that the browser uses. Defaults to
  `%LocalAppData%\UiPath\PIP Browser
  Profiles\BrowserType` if not set.
* `IsIncognito Boolean` - input
  `True` if you want to open the browser in
  incognito mode. By default it's set to `False`.
* `WebDriverMode NWebDriverMode` -
  Indicates how the WebDriver is used when opening a new browser
  session. The following options are available:
  + `Disabled` - Disables the use of
    WebDriver.
  + `WithGUI` - The GUI of the browser is
    displayed.
  + `Headless` - The browser is launched
    silently, with no GUI.
* `Timeout Double` - Specify a number
  of seconds for which to wait for the activity to be executed before
  throwing an error. The default value is 30 seconds. When indicating
  a window in a Remote Desktop environment, the Timeout default
  setting is set to 60 seconds.
* `InteractionMode
  NInteractionMode`:
  + `HardwareEvents` - Uses the hardware
    driver to perform the action. This is the slowest API, it
    cannot work in the background, but it is compatible with all
    desktop apps.
  + `Simulate` - Simulates the action using
    accessibility APIs. Recommended in browser automation, Java
    apps, or SAP. More reliable than Hardware Events. Sends all
    text in a single action. Works even if the target
    application is not in focus. Please test if your target
    application UI element supports this.
  + `DebuggerApi` - Performs actions using
    debugger APIs. Works only for Chromium elements. Sends all
    text in one go. Works even if target app is not in focus.
    For more details, check out this [page](https://docs.uipath.com/zh-CN/studio/docs/chromium-api).
  + `WindowMessages` - Sends the mouse and
    keyboard input through Win32 messages. Recommended for
    desktop apps. Usually more reliable than Hardware Events.
    Sends all text in a single action. Works even if target app
    is not in focus. Please test if your target application UI
    element supports this.
  + `Background` - Runs actions in the
    background. Tries to use either Simulate or Chromium API
    where possible, while complex APIs (image, native text)
    run as usual, in the foreground. It is highly recommended to
    use this API with the [Verify Execution](https://docs.uipath.com/zh-CN/activities/other/latest/user-guide/project-settings-ui-automation)
    feature.
* `OpenMode NAppOpenMode` - choose when
  to open the app:
  + `Never` (never open the
    application)
  + `IfNotOpen` (open only if the
    application is closed, this is the default selection, only
    works if `FilePath` or `URL`
    are provided)
  + `Always` (open another instance of the
    application even if one is already open, only works if
    `FilePath` or `URL` are
    provided)
* `WindowResize NWindowResize` - choose
  the size of the window:
  + `None`
  + `Maximize`
  + `Restore`
  + `Minimize`
* `UserDataFolderMode
  BrowserUserDataFolderMode` - The
  `UserDataFolderMode` you want to set. It is used
  to start the browser with a specific user data folder.
  + `Automatic` - Picture In Picture mode
    uses a different folder than the default mode, automatically
    generated if `UserDataFolderPath` is not
    set.
  + `DefaultFolder` - Uses the default
    browser folder, no matter if it runs in the main or PIP
    session.
  + `CustomFolder` - Uses the folder
    specified in `UserDataFolderPath` or an auto
    generated path if `UserDataFolderPath` is not
    set.
* `UserDataFolderPath String` - The
  user data folder that the browser uses. Defaults to
  `%LocalAppData%\UiPath\PIP Browser
  Profiles\BrowserType` if not set.
* `IsIncognito Boolean` - input
  `True` if you want to open the browser in
  incognito mode. By default it's set to `False`.
* `WebDriverMode NWebDriverMode` -
  Indicates how the WebDriver is used when opening a new browser
  session. The following options are available:
  + `Disabled` - Disables the use of
    WebDriver.
  + `WithGUI` - The GUI of the browser is
    displayed.
  + `Headless` - The browser is launched
    silently, with no GUI.

appName String : 要附加到的应用程序的名称。此参数适用于桌面应用程序。

appVersion String : 要附加到的应用程序的版本。此参数适用于桌面应用程序。

Open(TargetAppModel, TargetAppOptions)

打开要在用户界面自动化中使用的特定桌面应用程序或网页,由 TargetAppModel 对象标识。

Open(
    TargetAppModel targetApp,
    [TargetAppOptions targetAppOptions])
Open(
    TargetAppModel targetApp,
    [TargetAppOptions targetAppOptions])

targetApp TargetAppModel :要附加到的目标应用程序或网页。它是TargetAppModel类型的对象,提供有关应用程序的信息:

* `Selector` - An XML fragment that stores the
  attributes of a user interface element.
* `FilePath` - If the application is not a web
  browser, specifies the full path of the executable file to
  open.
* `Arguments` - If the application is not a web
  browser, you can specify parameters to pass to the target
  application at startup.
* `Url`
  - If the application is a web browser, specifies the URL of the web
  page to open.
* `Title` - The title of the application or
  browser.
* `Selector` - An XML fragment that stores the
  attributes of a user interface element.
* `FilePath` - If the application is not a web
  browser, specifies the full path of the executable file to
  open.
* `Arguments` - If the application is not a web
  browser, you can specify parameters to pass to the target
  application at startup.
* `Url`
  - If the application is a web browser, specifies the URL of the web
  page to open.
* `Title` - The title of the application or
  browser.

targetAppOptions :用于附加到应用程序或网页的其他选项和设置:

* `Timeout Double` - Specify a number of seconds
  for which to wait for the activity to be executed before throwing an
  error. The default value is 30 seconds. When indicating a window in
  a Remote Desktop environment, the Timeout default setting is set to
  60 seconds.
* `InteractionMode NInteractionMode`:
  + `HardwareEvents` - Uses the hardware driver
    to perform the action. This is the slowest API, it cannot
    work in the background, but it is compatible with all
    desktop apps.
  + `Simulate` - Simulates the action using
    accessibility APIs. Recommended in browser automation, Java
    apps, or SAP. More reliable than Hardware Events. Sends all
    text in a single action. Works even if the target
    application is not in focus. Please test if your target
    application UI element supports this.
  + `DebuggerApi` - Performs actions using
    debugger APIs. Works only for Chromium elements. Sends all
    text in one go. Works even if target app is not in focus.
    For more details, check out this [page](https://docs.uipath.com/studio/docs/chromium-api).
  + `WindowMessages` - Sends the mouse and
    keyboard input through Win32 messages. Recommended for
    desktop apps. Usually more reliable than Hardware Events.
    Sends all text in a single action. Works even if target app
    is not in focus. Please test if your target application UI
    element supports this.
  + `Background` - Runs actions in the
    background. Tries to use either Simulate or Chromium API
    where possible, while complex APIs (image, native text)
    run as usual, in the foreground. It is highly recommended to
    use this API with the [Verify Execution](https://docs.uipath.com/activities/other/latest/user-guide/project-settings-ui-automation)
    feature.
* `OpenMode NAppOpenMode` - choose when to open
  the app:
  + `Never` (never open the application)
  + `IfNotOpen` (open only if the application is
    closed, this is the default selection, only works if
    `FilePath` or `URL` are
    provided)
  + `Always` (open another instance of the
    application even if one is already open, only works if
    `FilePath` or `URL` are
    provided)
* `WindowResize NWindowResize` - choose the size
  of the window:
  + `None`
  + `Maximize`
  + `Restore`
  + `Minimize`
* `UserDataFolderMode BrowserUserDataFolderMode`
  - The `UserDataFolderMode` you want to set. It is
  used to start the browser with a specific user data folder.
  + `Automatic` - Picture In Picture mode uses a
    different folder than the default mode, automatically
    generated if `UserDataFolderPath` is not
    set.
  + `DefaultFolder` - Uses the default browser
    folder, no matter if it runs in the main or PIP
    session.
  + `CustomFolder` - Uses the folder specified in
    `UserDataFolderPath` or an auto generated
    path if `UserDataFolderPath` is not set.
* `UserDataFolderPath String` - The user data
  folder that the browser uses. Defaults to
  `%LocalAppData%\UiPath\PIP Browser
  Profiles\BrowserType` if not set.
* `IsIncognito Boolean` - input
  `True` if you want to open the browser in
  incognito mode. By default it's set to `False`.
* `WebDriverMode NWebDriverMode` - Indicates how
  the WebDriver is used when opening a new browser session. The
  following options are available:
  + `Disabled` - Disables the use of
    WebDriver.
  + `WithGUI` - The GUI of the browser is
    displayed.
  + `Headless` - The browser is launched
    silently, with no GUI.
* `Timeout Double` - Specify a number of seconds
  for which to wait for the activity to be executed before throwing an
  error. The default value is 30 seconds. When indicating a window in
  a Remote Desktop environment, the Timeout default setting is set to
  60 seconds.
* `InteractionMode NInteractionMode`:
  + `HardwareEvents` - Uses the hardware driver
    to perform the action. This is the slowest API, it cannot
    work in the background, but it is compatible with all
    desktop apps.
  + `Simulate` - Simulates the action using
    accessibility APIs. Recommended in browser automation, Java
    apps, or SAP. More reliable than Hardware Events. Sends all
    text in a single action. Works even if the target
    application is not in focus. Please test if your target
    application UI element supports this.
  + `DebuggerApi` - Performs actions using
    debugger APIs. Works only for Chromium elements. Sends all
    text in one go. Works even if target app is not in focus.
    For more details, check out this [page](https://docs.uipath.com/zh-CN/studio/docs/chromium-api).
  + `WindowMessages` - Sends the mouse and
    keyboard input through Win32 messages. Recommended for
    desktop apps. Usually more reliable than Hardware Events.
    Sends all text in a single action. Works even if target app
    is not in focus. Please test if your target application UI
    element supports this.
  + `Background` - Runs actions in the
    background. Tries to use either Simulate or Chromium API
    where possible, while complex APIs (image, native text)
    run as usual, in the foreground. It is highly recommended to
    use this API with the [Verify Execution](https://docs.uipath.com/zh-CN/activities/other/latest/user-guide/project-settings-ui-automation)
    feature.
* `OpenMode NAppOpenMode` - choose when to open
  the app:
  + `Never` (never open the application)
  + `IfNotOpen` (open only if the application is
    closed, this is the default selection, only works if
    `FilePath` or `URL` are
    provided)
  + `Always` (open another instance of the
    application even if one is already open, only works if
    `FilePath` or `URL` are
    provided)
* `WindowResize NWindowResize` - choose the size
  of the window:
  + `None`
  + `Maximize`
  + `Restore`
  + `Minimize`
* `UserDataFolderMode BrowserUserDataFolderMode`
  - The `UserDataFolderMode` you want to set. It is
  used to start the browser with a specific user data folder.
  + `Automatic` - Picture In Picture mode uses a
    different folder than the default mode, automatically
    generated if `UserDataFolderPath` is not
    set.
  + `DefaultFolder` - Uses the default browser
    folder, no matter if it runs in the main or PIP
    session.
  + `CustomFolder` - Uses the folder specified in
    `UserDataFolderPath` or an auto generated
    path if `UserDataFolderPath` is not set.
* `UserDataFolderPath String` - The user data
  folder that the browser uses. Defaults to
  `%LocalAppData%\UiPath\PIP Browser
  Profiles\BrowserType` if not set.
* `IsIncognito Boolean` - input
  `True` if you want to open the browser in
  incognito mode. By default it's set to `False`.
* `WebDriverMode NWebDriverMode` - Indicates how
  the WebDriver is used when opening a new browser session. The
  following options are available:
  + `Disabled` - Disables the use of
    WebDriver.
  + `WithGUI` - The GUI of the browser is
    displayed.
  + `Headless` - The browser is launched
    silently, with no GUI.

Open(String, String, String, NAppOpenMode, NWindowResize, NInteractionMode)

打开要在用户界面自动化中使用的特定桌面应用程序或网页,由对象存储库中的屏幕名称以及应用程序或网页的其他自定义项标识。

Open(
    string screenName,
    [string appName],
    [string appVersion],
    [NAppOpenMode openMode],
    [NWindowResize windowResize],
    [NInteractionMode interactionMode])
Open(
    string screenName,
    [string appName],
    [string appVersion],
    [NAppOpenMode openMode],
    [NWindowResize windowResize],
    [NInteractionMode interactionMode])

screeName String :要关注的屏幕的名称,以字符串形式记录在对象存储库中。

appName String : 要附加到的应用程序的名称。此参数适用于桌面应用程序。

appVersion String : 要附加到的应用程序的版本。此参数适用于桌面应用程序。

openMode NAppOpenMode :选择打开目标应用程序以执行自动化的时间:

* `Never` (never open the application)
* `IfNotOpen` (open only if the application is closed,
  this is the default selection, only works if the
  `Url` parameter is configured)
* `Always` - (open another instance of the application
  even if one is already open, only works if the `Url`
  parameter is configured).
* `Never` (never open the application)
* `IfNotOpen` (open only if the application is closed,
  this is the default selection, only works if the
  `Url` parameter is configured)
* `Always` - (open another instance of the application
  even if one is already open, only works if the `Url`
  parameter is configured).

NWindowResize :选择窗口的大小:

* `None`
* `Maximize`
* `Restore`
* `Minimize`
* `None`
* `Maximize`
* `Restore`
* `Minimize`

NInteractionMode :选择机器人应用于与目标应用程序交互的 API:

* `HardwareEvents` - Uses the hardware driver to
  perform the action. This is the slowest API, it cannot work in
  the background, but it is compatible with all desktop apps.
* `Simulate` - Simulates the action using accessibility
  APIs. Recommended in browser automation, Java apps, or SAP. More
  reliable than Hardware Events. Sends all text in a single action.
  Works even if the target application is not in focus. Please test if
  your target application UI element supports this.
* `DebuggerApi` - Performs actions using debugger APIs.
  Works only for Chromium elements. Sends all text in one go. Works
  even if target app is not in focus. For more details, check out this
  [page](https://docs.uipath.com/studio/docs/chromium-api).
* `WindowMessages` - Sends the mouse and keyboard input
  through Win32 messages. Recommended for desktop apps. Usually more
  reliable than Hardware Events. Sends all text in a single action.
  Works even if target app is not in focus. Please test if your target
  application UI element supports this.
* `Background` - Runs actions in the background. Tries
  to use either Simulate or Chromium API where possible, while complex
  APIs (image, native text) run as usual, in the foreground. It is
  highly recommended to use this API with the [Verify Execution](https://docs.uipath.com/activities/other/latest/user-guide/project-settings-ui-automation)
  feature.
* `HardwareEvents` - Uses the hardware driver to
  perform the action. This is the slowest API, it cannot work in
  the background, but it is compatible with all desktop apps.
* `Simulate` - Simulates the action using accessibility
  APIs. Recommended in browser automation, Java apps, or SAP. More
  reliable than Hardware Events. Sends all text in a single action.
  Works even if the target application is not in focus. Please test if
  your target application UI element supports this.
* `DebuggerApi` - Performs actions using debugger APIs.
  Works only for Chromium elements. Sends all text in one go. Works
  even if target app is not in focus. For more details, check out this
  [page](https://docs.uipath.com/zh-CN/studio/docs/chromium-api).
* `WindowMessages` - Sends the mouse and keyboard input
  through Win32 messages. Recommended for desktop apps. Usually more
  reliable than Hardware Events. Sends all text in a single action.
  Works even if target app is not in focus. Please test if your target
  application UI element supports this.
* `Background` - Runs actions in the background. Tries
  to use either Simulate or Chromium API where possible, while complex
  APIs (image, native text) run as usual, in the foreground. It is
  highly recommended to use this API with the [Verify Execution](https://docs.uipath.com/zh-CN/activities/other/latest/user-guide/project-settings-ui-automation)
  feature.

以无头模式运行网页驱动程序模式

要在无头配置中操作网页驱动程序模式,这些步骤可以用作指南。

首先为屏幕定义变量。使用函数 uiAutomation.Open 在您选择的浏览器中打开一个新应用程序 - 在本例中为 Edge。之后,在重载中使用 Options 类来指定某些浏览器选项。在这些选项中,将 webDriverMode 设置为 NWebDriverMode.Headless

相应的代码如下所示:

var screen = uiAutomation.Open(Descriptors.NewApplication.Edge, Options.AppOpen().WithBrowserOptions(webDriverMode: NWebDriverMode.Headless));
var screen = uiAutomation.Open(Descriptors.NewApplication.Edge, Options.AppOpen().WithBrowserOptions(webDriverMode: NWebDriverMode.Headless));

此代码用于将网页驱动程序设置为无头模式,从而在无需看到打开浏览器的情况下启用浏览器自动化。

此页面有帮助吗?

连接

需要帮助? 支持

想要了解详细内容? UiPath Academy

有问题? UiPath 论坛

保持更新