Run JavaScript action

The Run JavaScript action in the Browser package executes JavaScript on a web page and on web pages that have iFrames. This action also allows you to run a JavaScript snippet in desktop Chromium Embedded Framework (CEF) applications.

Settings

Note:
  • On macOS platform, this action supports Google Chrome and Safari browsers.
  • On Windows platform, this action supports Google Chrome and Chromium-based Microsoft Edge browsers.
  • This action supports CEF-based desktop applications.
  • When you use this action to execute a JavaScript that contains a single-line comment as the last line of the JavaScript (for example, //comment), it can cause the Automation Anywhere plugin to become unstable. We recommend that you either remove the comment at the end of the JavaScript or convert it to a multi-line comment (for example, /* comment */).
  • Select the browser tab from the list of active supported browser tabs or insert a window variable. To run a JavaScript snippet in CEF applications, use the Application tab. From the Application tab, select the specific CEF application from the list of applications. A CEF application integrates web browser functionality by embedding Chromium into a desktop application.
    Important:
    • To automate desktop applications that use CEF framework, you must develop and run your automations in elevated mode. See Automate applications running as an admin user.
    • To automate CEF applications, ensure you use the Browser package version 3.13.1 and later.
    Note:
    • Automating cross domain iFrame in CEF applications is not supported.
    • CEF applications will not be listed under the Browser tab.

    您可以使用正则表达式 (regex) 来标识窗口标题。 将每个正则表达式条件选择为字符串模式,然后输入值。 默认情况下,窗口标题字段区分大小写。

    要识别浏览器标题,您可以启用区分大小写选项以匹配字母大小写,或禁用该选项以识别字母大小写不匹配的窗口标题。
    Note: 确保您系统上安装的最低 Bot Agent 版本是随 Automation 360 v.26 发布的版本。 如果存在随 Automation 360 v.25 或更早版本发布的 Bot Agent 版本,则默认情况下,将仅通过匹配字母大小写(区分大小写)识别窗口标题。
    例如,要匹配所有以单词开头、后跟 - Notepad 的窗口标题名称,您可以输入字符串* -Notepad,或者仅为与此模式匹配的窗口标题使用模式((\w)\s)*document-Notepad
    Note:
    • 当您使用类型为字符串的正则表达式,并将 -title 作为任何 action 的窗口标题的输入值时,bot 可能会遇到运行时错误。 为了防止运行时错误,请确保在将字符串输入添加为 *-title 时,具有特定标题的应用程序已打开。 星号 (*) 只是一个字符,而不是通配符。
    • 当您使用类型为 Pattern 的正则表达式,并将 -title 作为任何 action 的窗口标题的输入值时,bot 可能会遇到运行时错误,因为输入值 *-title 是不正确的。

      请确保使用有效的正则表达式模式。

  • 选择以下选项之一:
    • 导入现有文件选项中,选择一个现有 JavaScript 文件。
      Note: 如果从桌面上的文件上传脚本,则文件和任何依赖项必须位于独立文件夹中。 当您选择待上传文件,上传所有同等级的文件和文件夹。
    • 手动输入选项中,输入 JavaScript
  • Optional: Use the Capture object option to capture the iFrames.
    Note:
    • The Capture object feature is used only to run JavaScript inside an iFrame.
    • Support to run JavaScript inside an iFrame is available only for the Google Chrome browser.
    The following object properties are selected by default when capturing IFrames:
    • Browser type
    • Technology type
    • Control type
    • HTML tag
    • DOMXPath
    • HTML HasFrame
    • HTML FramePath
    • FrameDOMXPath
    • Path
    • Role
    • HTML FrameSrc
  • 可选:后超时字段中,输入 bot 必须等待浏览器操作完成的秒数。
    推荐: 输入至少 9 秒的超时值。
  • Optional: In the Save the outcome to a variable field, select a variable to hold the action output. The Control Room shows a descriptive default variable name. If you create several output variables, subsequent variable names are appended with a -1, -2, -3, and so on to avoid duplication.
    Note: This action supports String, Number, and Boolean JavaScript types which correspond to the same variable types in bot variables, or to the bot variable type Any.
Recommendation:
  • Do not use Jquery with the JavaScript package.
  • Use the Try/Catch actions from the Error handler in the JavaScript function.
  • Call a JavaScript function before declaring it.

Watch the following video on using the Run JavaScript action from the Browser package to execute JavaScript directly within an existing browser window:

Automating object-based applications

We recommend that you use the Recorder for object-based automations instead of Run JavaScript action. If you use Run JavaScript action to automate dynamic web pages and if there is a change in control hierarchy or properties, then you must re-write the entire script. Use the Run JavaScript action only to execute external scripts in any application.

You can use the Recorder to automate applications using other available technologies if you are unable to capture using the default HTML technology. Ensure that the accessibility for your application is enabled and is not blocked by any company policy before you use a different technology to automate. We recommend you open Google Chrome with the flag --force-renderer-accessibility.

Enable application accessibility