Table of Contents

Class WebDriverExtensions

Namespace
OpenQA.Selenium.Support.Extensions
Assembly
WebDriver.Support.dll

Provides extension methods for convenience in using WebDriver.

public static class WebDriverExtensions
Inheritance
WebDriverExtensions
Inherited Members

Methods

ExecuteJavaScript(IWebDriver, string, params object?[])

Executes JavaScript in the context of the currently selected frame or window

public static void ExecuteJavaScript(this IWebDriver driver, string script, params object?[] args)

Parameters

driver IWebDriver

The driver instance to extend.

script string

The JavaScript code to execute.

args object[]

The arguments to the script.

Exceptions

WebDriverException

Thrown if this IWebDriver instance does not implement IJavaScriptExecutor

ExecuteJavaScript<T>(IWebDriver, string, params object?[])

Executes JavaScript in the context of the currently selected frame or window

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

Parameters

driver IWebDriver

The driver instance to extend.

script string

The JavaScript code to execute.

args object[]

The arguments to the script.

Returns

T

The value returned by the script.

Type Parameters

T

Expected return type of the JavaScript execution.

Exceptions

WebDriverException

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

TakeScreenshot(IWebDriver)

Gets a Screenshot object representing the image of the page on the screen.

public static Screenshot TakeScreenshot(this IWebDriver driver)

Parameters

driver IWebDriver

The driver instance to extend.

Returns

Screenshot

A Screenshot object containing the image.

Exceptions

WebDriverException

Thrown if this IWebDriver instance does not implement ITakesScreenshot, or the capabilities of the driver indicate that it cannot take screenshots.