IJavaScriptExecutor ExecuteScript Method WebDriver
Executes JavaScript in the context of the currently selected frame or window.

Namespace: OpenQA.Selenium
Assembly: WebDriver (in WebDriver.dll) Version: 2.35.0.0 (2.35.0.0)
Syntax

Object ExecuteScript(
	string script,
	params Object[] args
)

Parameters

script
Type: OnlineSystem String
The JavaScript code to execute.
args
Type:  OnlineSystem Object 
The arguments to the script.

Return Value

The value returned by the script.
Remarks

The ExecuteScript(String,  Object )method executes JavaScript in the context of the currently selected frame or window. This means that "document" will refer to the current document. If the script has a return value, then the following steps will be taken:

Arguments must be a number (which will be converted to a OnlineInt64), a OnlineBoolean, a OnlineString or a IWebElement. An exception will be thrown if the arguments do not meet these criteria. The arguments will be made available to the JavaScript via the "arguments" magic variable, as if the function were called via "Function.apply"

See Also