Run JavaScript action

The Run JavaScript action in the Browser package executes JavaScript on a web page and on web pages that have iFrames.

Settings

Note:
  • This action supports Google Chrome and Chromium-based Microsoft Edge browsers.
  • 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.

    You can use a regular expression (regex) to identify a window title. Select the regular expression condition as either String or a Pattern and then enter the value. By default, the Window title field is case-sensitive.

    To identify a browser title, you can enable the Case sensitive option to match the letter case, or disable the option to identify a window title where the letter case does not match.
    Note: Ensure that the minimum Bot Agent version installed on your system is the version that was released with Automation 360 v.26. If you have a Bot Agent version released with Automation 360 v.25 or earlier, then by default, the window title will be identified only with matching letter case (case-sensitive).
    For example, to match all window title names beginning with a word followed by - Notepad, you can enter the String value as * -Notepad, or use Pattern value as ((\w)\s)*document-Notepad for only those window titles that match this pattern.
    Note:
    • When you use a regular expression of type String with -title as the input value for a window title in any action, the bot might encounter a run time error. To prevent the run time error, ensure that when you add the string input as *-title, the application with the specific title is open. The asterisk (*) is just a character, not a wild card character.
    • When you use a regular expression of type Pattern with -title as the input value for a window title in any action, the bot might encounter a run time error because the input value *-title is incorrect.

      Ensure that you use valid regex patterns.

  • Choose one of the following options:
    • In the Import existing file option, select an existing JavaScript file.
      Note: If you are uploading a script from a file on your desktop, the file and any dependencies must be in a standalone folder. When you select a file for upload, all files and folders at the same folder level are uploaded.
    • In the Manual input option, enter the 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
  • Optional: In the Time out after field, enter the number of seconds the bot must wait for the browser action to complete.
    Recommended: Enter a timeout value of at least 9 seconds.
  • 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