Execute JavaScript

Executes JavaScript code in the current frame or window of the selected WebDriver. Data can be transferred between KNIME and the JavaScript code, by specifying a return type for the executed code and/or selecting input columns which provide argument values for the executed code.

Arguments can be accessed within JavaScript code through the arguments array. The following argument and return data types are supported:

JavaScript KNIME Cell KNIME Flow Variable
HTML Element WebElement
Decimal Number Double Double
Non-decimal Number Long Long, Int
Boolean Boolean Boolean
String String String
Array List, JSON Double, Long, Int, Boolean, String Array
Object JSON

The following snippet will return a JSON object which is mapped to a JSON cell in KNIME. For this, set the “Return type” to “JSON”:

const result = { property1: 'a', property2: 2, property3: [ 'b', 'c', 'c' ] };
return result;

In case you need to execute code asynchronously, enable the [asyncCallbackMethod] argument. In this case, the last argument given to the executed code is the callback which signals that the code has finished execution. In case you need to return results from your asynchronous code, provide it as argument to the callback method. For example, the following JavaScript code causes the browser to sleep for five seconds, then the execution continues:

const callback = arguments[arguments.length - 1]; // last argument is callback
window.setTimeout(function() {
  console.log('finished');
  callback(); // invoke the callback to continue execution
}, 5000);
        

Timeouts for asynchronous execution can be configured in the Start WebDriver node in the “Timeouts” tab: Script timeout.

Options

Input
Input column which provides the WebDriver(s)
Arguments
Select columns from the input table or flow variables, which provide arguments for the executed code snippet. The selected entries are available in code in the listed order via the arguments array. Enable the last entry [asyncCallbackMethod] in case you’re running an asynchronous script to be able to signal end of execution.
Return type
The return type of the executed JavaScript code in order to map to an appropriate KNIME type, which will be appended as additional output column. Select “None”, in case the code does not return any value.
Column name
The name of the appended column with the result
JavaScript code
The JavaScript code to execute

Input Ports

Icon
Table with a column providing a WebDriver

Output Ports

Icon
Same as input table, optionally with an additional column with the return values of each JavaScript execution.

Views

This node has no views

Workflows

Links

Developers

You want to see the source code for this node? Click the following button and we’ll use our super-powers to find it for you.