Execute JavaScript

This Node Is Deprecated — This version of the node has been replaced with a new and improved version. The old version is kept for backwards-compatibility, but for all new workflows we suggest to use the version linked below.
Go to Suggested ReplacementExecute 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
HTML element WebElementValue
Decimal DoubleValue
Non-decimal LongValue
boolean BooleanValue
String and other cases StringValue

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:

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

Hint: In case you want to return complex data from your JavaScript code (objects or arrays), you can serialize them as follows and use the return type “String”:

var complexObject = {
  property1: 'foo',
  property2: [ 'bar', 'baz' ],
  property3: 5  
};
return JSON.stringify(complexObject);
        

Afterwards, you can make use of KNIME’s String to JSON node to convert the string into a JSON cell.

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.