WebDriverExtensionsExecuteJavaScriptT Method (IWebDriver, String, Object)WebDriver
Executes JavaScript in the context of the currently selected frame or window

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

public static T ExecuteJavaScript<T>(
	this IWebDriver driver,
	string script,
	params Object[] args
)

Parameters

driver
Type: OpenQA.SeleniumIWebDriver
The driver instance to extend.
script
Type: SystemString
The JavaScript code to execute.
args
Type: SystemObject
The arguments to the script.

Type Parameters

T
Expected return type of the JavaScript execution.

Return Value

Type: T
The value returned by the script.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type IWebDriver. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).
Exceptions

ExceptionCondition
WebDriverExceptionThrown if this IWebDriver instance does not implement IJavaScriptExecutor, or if the actual return type of the JavaScript execution does not match the expected type.
See Also

Reference