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

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

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

Parameters

script
Type: SystemString
The JavaScript code to execute.
args
Type: SystemObject
The arguments to the script.

Return Value

Type: Object
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 Int64), a Boolean, a String 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

Reference