Run Web JavaScript

A Run Web JavaScript building block is used to execute a piece of JavaScript in an open browser window. This can for instance be used to trigger events on a web page, such as “exit intent”. Please note that this block only works with browser windows that were previously opened using the Start Web Browser block or their “child” windows.

Fully expanded, the Run Web JavaScript block shows the following properties:

run-web-javascript-block

The Block Header (“Run Web Javascript”)

The green input connector in the header is used to trigger the block to start executing.

The green output connector in the header triggers when the javascript has been executed in the browser window.

The title of the block (“Run Web Javascript”) can be changed by double-clicking on it and typing in a new title.

Script

The javascript to be run. Do not include <script> tags. Can contain tokens for field values (added below).

Right-click and select “Insert token” to insert one or more field tokens.

Capture

Click to capture keystrokes into the script. This makes it easy to use special keys and key combinations such as CTRL+C, ENTER, etc.

Special keys and key combinations can also be entered manually by wrapping the key(s) with double percentage signs (%%). For instance: %%CTRL+P%% or %%ENTER%%.

Text fields

Fields that enable the use of external values in the script.

To use the value of an added field, right-click the text field above and select “Insert token” and then insert this field’s name.

Add field

Add a field to be used in the typed text.

Add Argument

Add one or more arguments that will be sent to the javascript.

Result

This property contains the result of the executed javascript in the format defined below.

Result as

Select what type the result from the executed JavaScript should be handled as in LEAPWORK.

By choosing “Web Element”, it’s possible to perform a javascript action that returns a web element that can be used as the source element in another building block.

Browser window

By setting this property, the building block will use a specific browser window.

 

Use case example: Run web JavaScript - Handling the odd cases

 

Updated March 27th 2017.