Skip to main content

GUI: Inject JavaScript

Description

Inject JavaScript runs custom JavaScript code directly in the active browser tab during a web automation workflow. Use this step when standard web locators and built-in actions cannot interact with a control as expected — for example, to set hidden field values, trigger custom events, or click dynamically generated elements. You can retrieve input fields from the page, write your own scripts in the editor, and return values to downstream workflow steps using a structured return format. If you need to run JavaScript in a different tab or window, add a Switch Window step before this one.

Note

Inject JavaScript step works on active browser tab. In case where you want to execute JavaScript in another tab/window opened during automation, use switch window first and then add Inject JavaScript step

Configurations

Field NameDescription
Step NameName of the step. The name must be unique in a single workflow.
The data type is string, and the field is mandatory.
Web Browser NameYou can select any one web browser from the given list. Note: You must select the same web browser which was selected in the Start Browser step.
Iframe indicesSpecify Iframe Indices value. Specifying iframe indices ensures that the target element is identified correctly within the nested frame structure.
You can provide comma-separated values.
For example: 0,1,2…..
Iframe XpathIframe Xpath is a uniquely generated path that represents the location of an <iframe> or <frame> relative to the top-level window.

Iframe Xpath identifies each frame using a unique attribute such as id, name, or title if available, for example, iframe[@id='mainFrame'].

If no such attributes exist, the frame is identified by its position among sibling frames, like iframe[2] for the second iframe.

For nested structures, each frame is joined in sequence to form a full path. For example, if an element is inside an iframe[@id='outer'], which contains a frameset with a frame[@name='middle'], and that frame contains iframe[@title='inner'], the generated path would be:
iframe[@id='outer'];frame[@name='middle'];iframe[@title='inner'].

Note: If an iframe or frame has no id, name, or title, its origin (i.e., the src URL) will be used as a fallback in the path for unique identification. For example: iframe[@origin='https://example.com'].
Frame IDProvide the current Iframe Id to target a specific iframe to perform the action.
Default Value: frameID
Left Pane:
Get Input FieldsClick to get a list of all input fields that can be used as a part of Inject Java Script.
Code Snippets:
Sample CodeDouble click Sample Code to populate sample code in the Inject Java Script right hand pane. Here you will find an example to make fields available to next step.
Partial pseudo code for making multiple fields available to next step,
var FieldName = "FieldName"; var FieldValue = "FieldValue"; var FieldName2 = "FieldName2"; var FieldValue2 = "FieldValue2"; return "<<>>"+FieldName+"::"+FieldValue+"<<>>;<<>>"+FieldName2+"::"+FieldValue2+"<<>>";
Right Pane:
Inject JavaScriptWrite the Java Script in the space provided.
Following, is a sample Java Script showing how to set value and click a button.
In this case the code sets values of username and password and clicks a login button. var chkPrint = document.getElementsByName('uid')[0].value = "mngr169997"; document.getElementsByName('password')[0].value = "YvynEtA"; document.getElementsByName('btnLogin')[0].click();