It is possible to run JavaScript code in the context of an element or in global context.

Element Context

If you need access to  a specific property of an element and it is not available via HTMLObject API follow this pattern:

 * el - reserved reference to the DOM element
 * <property_name> - name of a property to read
 * <html_object> - an object found on the page with SeS or Navigator.Find
var propertyValue = Navigator.ExecJS('return el.<property_name>;', <html_object>);

// Example 1
var formAction = Navigator.ExecJS('return el.formAction;', SeS("Username_"));

// Example 2
var formAction = Navigator.ExecJS("return el.formAction;", Navigator.Find("//input[@id='MainContent_LoginUser_UserName']"));

To make it compatible with Selenium WebDriver use arguments[0] instead of el.

var formAction = Navigator.ExecJS('return arguments[0].formAction;', SeS("Username_"));

Global Context

To access parent document or window of a specific element use

 * <your_code> - JavaScript code to execute
 * <html_object> - an object found with SeS or Navigator.Find
var result = Navigator.ExecJS("<your_code>", <html_object>);

// Example 3
var url = Navigator.ExecJS("return document.location.href;", SeS("Username_")));

// Example 4
var url = Navigator.ExecJS("return document.location.href;", Navigator.Find("//input[@id='MainContent_LoginUser_UserName']"));

If you need to execute a code not related to a specific element (e.g. for the topmost document or window) do not pass second parameter to Navigator.ExecJS and assign the result of your code to execResult variable.

var url = Navigator.ExecJS("execResult = document.location.href;");