Table of Contents

Class JavaScriptEngine

Namespace
OpenQA.Selenium
Assembly
WebDriver.dll

Provides methods allowing the user to manage settings in the browser's JavaScript engine.

public class JavaScriptEngine : IJavaScriptEngine, IDisposable
Inheritance
JavaScriptEngine
Implements
Inherited Members

Constructors

JavaScriptEngine(IWebDriver)

Initializes a new instance of the JavaScriptEngine class.

public JavaScriptEngine(IWebDriver driver)

Parameters

driver IWebDriver

The IWebDriver instance in which the JavaScript engine is executing.

Properties

InitializationScripts

Gets the read-only list of initialization scripts added for this JavaScript engine.

public IReadOnlyList<InitializationScript> InitializationScripts { get; }

Property Value

IReadOnlyList<InitializationScript>

ScriptCallbackBindings

Gets the read-only list of bindings added for this JavaScript engine.

public IReadOnlyList<string> ScriptCallbackBindings { get; }

Property Value

IReadOnlyList<string>

Methods

AddInitializationScript(string, string)

Asynchronously adds JavaScript to be loaded on every document load.

public Task<InitializationScript> AddInitializationScript(string scriptName, string script)

Parameters

scriptName string

The friendly name by which to refer to this initialization script.

script string

The JavaScript to be loaded on every page.

Returns

Task<InitializationScript>

A task containing an InitializationScript object representing the script to be loaded on each page.

AddScriptCallbackBinding(string)

Asynchronously adds a binding to a callback method that will raise an event when the named binding is called by JavaScript executing in the browser.

public Task AddScriptCallbackBinding(string bindingName)

Parameters

bindingName string

The name of the callback that will trigger events when called by JavaScript executing in the browser.

Returns

Task

A task that represents the asynchronous operation.

ClearAll()

Asynchronously removes all bindings to JavaScript callbacks, all initialization scripts from being loaded for each document, and unpins all pinned scripts.

public Task ClearAll()

Returns

Task

A task that represents the asynchronous operation.

ClearInitializationScripts()

Asynchronously removes all intialization scripts from being loaded on every document load.

public Task ClearInitializationScripts()

Returns

Task

A task that represents the asynchronous operation.

ClearScriptCallbackBindings()

Asynchronously removes all bindings to JavaScript callbacks.

public Task ClearScriptCallbackBindings()

Returns

Task

A task that represents the asynchronous operation.

DisableDomMutationMonitoring()

Disables monitoring for DOM changes.

public Task DisableDomMutationMonitoring()

Returns

Task

A task that represents the asynchronous operation.

Dispose()

Releases all resources associated with this JavaScriptEngine.

public void Dispose()

Dispose(bool)

Releases all resources associated with this JavaScriptEngine.

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

true if the Dispose method was explicitly called; otherwise, false.

EnableDomMutationMonitoring()

Enables monitoring for DOM changes.

public Task EnableDomMutationMonitoring()

Returns

Task

A task that represents the asynchronous operation.

PinScript(string)

Pins a JavaScript snippet for execution in the browser without transmitting the entire script across the wire for every execution.

public Task<PinnedScript> PinScript(string script)

Parameters

script string

The JavaScript to pin

Returns

Task<PinnedScript>

A task containing a PinnedScript object to use to execute the script.

Exceptions

ArgumentNullException

If script is null.

RemoveInitializationScript(string)

Asynchronously removes JavaScript from being loaded on every document load.

public Task RemoveInitializationScript(string scriptName)

Parameters

scriptName string

The friendly name of the initialization script to be removed.

Returns

Task

A task that represents the asynchronous operation.

RemoveScriptCallbackBinding(string)

Asynchronously removes a binding to a JavaScript callback.

public Task RemoveScriptCallbackBinding(string bindingName)

Parameters

bindingName string

The name of the callback to be removed.

Returns

Task

A task that represents the asynchronous operation.

Reset()

Asynchronously removes all bindings to JavaScript callbacks, all initialization scripts from being loaded for each document, all pinned scripts, and stops listening for events.

public Task Reset()

Returns

Task

A task that represents the asynchronous operation.

StartEventMonitoring()

Asynchronously starts monitoring for events from the browser's JavaScript engine.

public Task StartEventMonitoring()

Returns

Task

A task that represents the asynchronous operation.

StopEventMonitoring()

Stops monitoring for events from the browser's JavaScript engine.

public void StopEventMonitoring()

UnpinScript(PinnedScript)

Unpins a previously pinned script from the browser.

public Task UnpinScript(PinnedScript script)

Parameters

script PinnedScript

The PinnedScript object to unpin.

Returns

Task

A task that represents the asynchronous operation.

Exceptions

ArgumentNullException

If script is null.

Events

DomMutated

Occurs when a value of an attribute in an element is being changed.

public event EventHandler<DomMutatedEventArgs> DomMutated

Event Type

EventHandler<DomMutatedEventArgs>

JavaScriptCallbackExecuted

Occurs when a JavaScript callback with a named binding is executed.

public event EventHandler<JavaScriptCallbackExecutedEventArgs> JavaScriptCallbackExecuted

Event Type

EventHandler<JavaScriptCallbackExecutedEventArgs>

JavaScriptConsoleApiCalled

Occurs when methods on the JavaScript console are called.

public event EventHandler<JavaScriptConsoleApiCalledEventArgs> JavaScriptConsoleApiCalled

Event Type

EventHandler<JavaScriptConsoleApiCalledEventArgs>

JavaScriptExceptionThrown

Occurs when an exeception is thrown by JavaScript being executed in the browser.

public event EventHandler<JavaScriptExceptionThrownEventArgs> JavaScriptExceptionThrown

Event Type

EventHandler<JavaScriptExceptionThrownEventArgs>