Table of Contents

Class DevToolsSession

Namespace
OpenQA.Selenium.DevTools
Assembly
WebDriver.dll

Represents a WebSocket connection to a running DevTools instance that can be used to send commands and recieve events.

public class DevToolsSession : IDevToolsSession, IDisposable
Inheritance
DevToolsSession
Implements
Inherited Members

Constructors

DevToolsSession(string)

Initializes a new instance of the DevToolsSession class, using the specified WebSocket endpoint.

[Obsolete("Use DevToolsSession(string endpointAddress, DevToolsOptions options)")]
public DevToolsSession(string endpointAddress)

Parameters

endpointAddress string

DevToolsSession(string, DevToolsOptions)

Initializes a new instance of the DevToolsSession class, using the specified WebSocket endpoint and specified DevTools options.

public DevToolsSession(string endpointAddress, DevToolsOptions options)

Parameters

endpointAddress string
options DevToolsOptions

Exceptions

ArgumentNullException

Fields

AutoDetectDevToolsProtocolVersion

A value indicating that the version of the DevTools protocol in use by the browser should be automatically detected.

public const int AutoDetectDevToolsProtocolVersion = 0

Field Value

int

Properties

ActiveSessionId

Gets or sets the active session ID of the connection.

public string ActiveSessionId { get; }

Property Value

string

CommandTimeout

Gets or sets the time to wait for a command to complete. Default is 30 seconds.

public TimeSpan CommandTimeout { get; set; }

Property Value

TimeSpan

Domains

Gets the version-independent domain implementation for this Developer Tools connection

public DevToolsDomains Domains { get; }

Property Value

DevToolsDomains

EndpointAddress

Gets the endpoint address of the session.

public string EndpointAddress { get; }

Property Value

string

Methods

Dispose()

Releases all resources associated with this DevToolsSession.

public void Dispose()

Dispose(bool)

Releases all resources associated with this DevToolsSession.

protected void Dispose(bool disposing)

Parameters

disposing bool

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

GetVersionSpecificDomains<T>()

Gets the version-specific implementation of domains for this DevTools session.

public T GetVersionSpecificDomains<T>() where T : DevToolsSessionDomains

Returns

T

The version-specific DevTools Protocol domain implementation.

Type Parameters

T

A DevToolsSessionDomains object containing the version-specific DevTools Protocol domain implementations.

SendCommand(string, string, JsonNode, CancellationToken, int?, bool)

Returns a JsonNode based on a command created with the specified command name and params.

public Task<JsonElement?> SendCommand(string commandName, string sessionId, JsonNode commandParameters, CancellationToken cancellationToken = default, int? millisecondsTimeout = null, bool throwExceptionIfResponseNotReceived = true)

Parameters

commandName string

The name of the command to send.

sessionId string

The sessionId of the command.

commandParameters JsonNode

The parameters of the command as a JsonNode object

cancellationToken CancellationToken

A CancellationToken object to allow for cancellation of the command.

millisecondsTimeout int?

The execution timeout of the command in milliseconds.

throwExceptionIfResponseNotReceived bool

true to throw an exception if a response is not received; otherwise, false.

Returns

Task<JsonElement?>

The command response object implementing the ICommandResponse<T> interface.

SendCommand(string, JsonNode, CancellationToken, int?, bool)

Returns a JsonNode based on a command created with the specified command name and params.

public Task<JsonElement?> SendCommand(string commandName, JsonNode commandParameters, CancellationToken cancellationToken = default, int? millisecondsTimeout = null, bool throwExceptionIfResponseNotReceived = true)

Parameters

commandName string

The name of the command to send.

commandParameters JsonNode

The parameters of the command as a JsonNode object

cancellationToken CancellationToken

A CancellationToken object to allow for cancellation of the command.

millisecondsTimeout int?

The execution timeout of the command in milliseconds.

throwExceptionIfResponseNotReceived bool

true to throw an exception if a response is not received; otherwise, false.

Returns

Task<JsonElement?>

The command response object implementing the ICommandResponse<T> interface.

SendCommand<TCommand>(TCommand, string, CancellationToken, int?, bool)

Sends the specified command and returns the associated command response.

public Task<ICommandResponse<TCommand>> SendCommand<TCommand>(TCommand command, string sessionId, CancellationToken cancellationToken = default, int? millisecondsTimeout = null, bool throwExceptionIfResponseNotReceived = true) where TCommand : ICommand

Parameters

command TCommand

The command to be sent.

sessionId string

The target session of the command

cancellationToken CancellationToken

A CancellationToken object to allow for cancellation of the command.

millisecondsTimeout int?

The execution timeout of the command in milliseconds.

throwExceptionIfResponseNotReceived bool

true to throw an exception if a response is not received; otherwise, false.

Returns

Task<ICommandResponse<TCommand>>

The command response object implementing the ICommandResponse<T> interface.

Type Parameters

TCommand

A command object implementing the ICommand interface.

SendCommand<TCommand>(TCommand, CancellationToken, int?, bool)

Sends the specified command and returns the associated command response.

public Task<ICommandResponse<TCommand>> SendCommand<TCommand>(TCommand command, CancellationToken cancellationToken = default, int? millisecondsTimeout = null, bool throwExceptionIfResponseNotReceived = true) where TCommand : ICommand

Parameters

command TCommand

The command to be sent.

cancellationToken CancellationToken

A CancellationToken object to allow for cancellation of the command.

millisecondsTimeout int?

The execution timeout of the command in milliseconds.

throwExceptionIfResponseNotReceived bool

true to throw an exception if a response is not received; otherwise, false.

Returns

Task<ICommandResponse<TCommand>>

The command response object implementing the ICommandResponse<T> interface.

Type Parameters

TCommand

A command object implementing the ICommand interface.

SendCommand<TCommand, TCommandResponse>(TCommand, CancellationToken, int?, bool)

Sends the specified command and returns the associated command response.

public Task<TCommandResponse> SendCommand<TCommand, TCommandResponse>(TCommand command, CancellationToken cancellationToken = default, int? millisecondsTimeout = null, bool throwExceptionIfResponseNotReceived = true) where TCommand : ICommand where TCommandResponse : ICommandResponse<TCommand>

Parameters

command TCommand

The command to send.

cancellationToken CancellationToken

A CancellationToken object to allow for cancellation of the command.

millisecondsTimeout int?

The execution timeout of the command in milliseconds.

throwExceptionIfResponseNotReceived bool

true to throw an exception if a response is not received; otherwise, false.

Returns

Task<TCommandResponse>

The command response object implementing the ICommandResponse<T> interface.

Type Parameters

TCommand

A command object implementing the ICommand interface.

TCommandResponse

A response object implementing the ICommandResponse interface.

Events

DevToolsEventReceived

Event raised an event notification is received from the DevTools session.

public event EventHandler<DevToolsEventReceivedEventArgs> DevToolsEventReceived

Event Type

EventHandler<DevToolsEventReceivedEventArgs>

LogMessage

Event raised when the DevToolsSession logs informational messages.

public event EventHandler<DevToolsSessionLogMessageEventArgs> LogMessage

Event Type

EventHandler<DevToolsSessionLogMessageEventArgs>