Table of Contents

Class TargetAdapter

Namespace
OpenQA.Selenium.DevTools.V147.Target
Assembly
Selenium.WebDriver.dll

Represents an adapter for the Target domain to simplify the command interface.

public class TargetAdapter
Inheritance
TargetAdapter
Inherited Members

Constructors

TargetAdapter(IDevToolsSession)

Initializes a new instance of the TargetAdapter class.

public TargetAdapter(IDevToolsSession session)

Parameters

session IDevToolsSession

The IDevToolsSession to be used with this adapter.

Exceptions

ArgumentNullException

If session is null.

Properties

Session

Gets the DevToolsSession associated with the adapter.

public IDevToolsSession Session { get; }

Property Value

IDevToolsSession

Methods

ActivateTarget(ActivateTargetCommandSettings, CancellationToken, int?, bool)

Activates (focuses) the target.

public Task<ActivateTargetCommandResponse?> ActivateTarget(ActivateTargetCommandSettings command, CancellationToken cancellationToken = default, int? millisecondsTimeout = null, bool throwExceptionIfResponseNotReceived = true)

Parameters

command ActivateTargetCommandSettings
cancellationToken CancellationToken
millisecondsTimeout int?
throwExceptionIfResponseNotReceived bool

Returns

Task<ActivateTargetCommandResponse>

AttachToBrowserTarget(AttachToBrowserTargetCommandSettings?, CancellationToken, int?, bool)

Attaches to the browser target, only uses flat sessionId mode.

public Task<AttachToBrowserTargetCommandResponse> AttachToBrowserTarget(AttachToBrowserTargetCommandSettings? command = null, CancellationToken cancellationToken = default, int? millisecondsTimeout = null, bool throwExceptionIfResponseNotReceived = true)

Parameters

command AttachToBrowserTargetCommandSettings
cancellationToken CancellationToken
millisecondsTimeout int?
throwExceptionIfResponseNotReceived bool

Returns

Task<AttachToBrowserTargetCommandResponse>

AttachToTarget(AttachToTargetCommandSettings, CancellationToken, int?, bool)

Attaches to the target with given id.

public Task<AttachToTargetCommandResponse> AttachToTarget(AttachToTargetCommandSettings command, CancellationToken cancellationToken = default, int? millisecondsTimeout = null, bool throwExceptionIfResponseNotReceived = true)

Parameters

command AttachToTargetCommandSettings
cancellationToken CancellationToken
millisecondsTimeout int?
throwExceptionIfResponseNotReceived bool

Returns

Task<AttachToTargetCommandResponse>

AutoAttachRelated(AutoAttachRelatedCommandSettings, CancellationToken, int?, bool)

Adds the specified target to the list of targets that will be monitored for any related target creation (such as child frames, child workers and new versions of service worker) and reported through attachedToTarget. The specified target is also auto-attached. This cancels the effect of any previous setAutoAttach and is also cancelled by subsequent setAutoAttach. Only available at the Browser target.

public Task<AutoAttachRelatedCommandResponse?> AutoAttachRelated(AutoAttachRelatedCommandSettings command, CancellationToken cancellationToken = default, int? millisecondsTimeout = null, bool throwExceptionIfResponseNotReceived = true)

Parameters

command AutoAttachRelatedCommandSettings
cancellationToken CancellationToken
millisecondsTimeout int?
throwExceptionIfResponseNotReceived bool

Returns

Task<AutoAttachRelatedCommandResponse>

CloseTarget(CloseTargetCommandSettings, CancellationToken, int?, bool)

Closes the target. If the target is a page that gets closed too.

public Task<CloseTargetCommandResponse> CloseTarget(CloseTargetCommandSettings command, CancellationToken cancellationToken = default, int? millisecondsTimeout = null, bool throwExceptionIfResponseNotReceived = true)

Parameters

command CloseTargetCommandSettings
cancellationToken CancellationToken
millisecondsTimeout int?
throwExceptionIfResponseNotReceived bool

Returns

Task<CloseTargetCommandResponse>

CreateBrowserContext(CreateBrowserContextCommandSettings, CancellationToken, int?, bool)

Creates a new empty BrowserContext. Similar to an incognito profile but you can have more than one.

public Task<CreateBrowserContextCommandResponse> CreateBrowserContext(CreateBrowserContextCommandSettings command, CancellationToken cancellationToken = default, int? millisecondsTimeout = null, bool throwExceptionIfResponseNotReceived = true)

Parameters

command CreateBrowserContextCommandSettings
cancellationToken CancellationToken
millisecondsTimeout int?
throwExceptionIfResponseNotReceived bool

Returns

Task<CreateBrowserContextCommandResponse>

CreateTarget(CreateTargetCommandSettings, CancellationToken, int?, bool)

Creates a new page.

public Task<CreateTargetCommandResponse> CreateTarget(CreateTargetCommandSettings command, CancellationToken cancellationToken = default, int? millisecondsTimeout = null, bool throwExceptionIfResponseNotReceived = true)

Parameters

command CreateTargetCommandSettings
cancellationToken CancellationToken
millisecondsTimeout int?
throwExceptionIfResponseNotReceived bool

Returns

Task<CreateTargetCommandResponse>

DetachFromTarget(DetachFromTargetCommandSettings, CancellationToken, int?, bool)

Detaches session with given id.

public Task<DetachFromTargetCommandResponse?> DetachFromTarget(DetachFromTargetCommandSettings command, CancellationToken cancellationToken = default, int? millisecondsTimeout = null, bool throwExceptionIfResponseNotReceived = true)

Parameters

command DetachFromTargetCommandSettings
cancellationToken CancellationToken
millisecondsTimeout int?
throwExceptionIfResponseNotReceived bool

Returns

Task<DetachFromTargetCommandResponse>

DisposeBrowserContext(DisposeBrowserContextCommandSettings, CancellationToken, int?, bool)

Deletes a BrowserContext. All the belonging pages will be closed without calling their beforeunload hooks.

public Task<DisposeBrowserContextCommandResponse?> DisposeBrowserContext(DisposeBrowserContextCommandSettings command, CancellationToken cancellationToken = default, int? millisecondsTimeout = null, bool throwExceptionIfResponseNotReceived = true)

Parameters

command DisposeBrowserContextCommandSettings
cancellationToken CancellationToken
millisecondsTimeout int?
throwExceptionIfResponseNotReceived bool

Returns

Task<DisposeBrowserContextCommandResponse>

ExposeDevToolsProtocol(ExposeDevToolsProtocolCommandSettings, CancellationToken, int?, bool)

Inject object to the target's main frame that provides a communication channel with browser target.

Injected object will be available as window[bindingName].

The object has the following API:

  • binding.send(json) - a method to send messages over the remote debugging protocol
  • binding.onmessage = json => handleMessage(json) - a callback that will be called for the protocol notifications and command responses.
public Task<ExposeDevToolsProtocolCommandResponse?> ExposeDevToolsProtocol(ExposeDevToolsProtocolCommandSettings command, CancellationToken cancellationToken = default, int? millisecondsTimeout = null, bool throwExceptionIfResponseNotReceived = true)

Parameters

command ExposeDevToolsProtocolCommandSettings
cancellationToken CancellationToken
millisecondsTimeout int?
throwExceptionIfResponseNotReceived bool

Returns

Task<ExposeDevToolsProtocolCommandResponse>

GetBrowserContexts(GetBrowserContextsCommandSettings?, CancellationToken, int?, bool)

Returns all browser contexts created with Target.createBrowserContext method.

public Task<GetBrowserContextsCommandResponse> GetBrowserContexts(GetBrowserContextsCommandSettings? command = null, CancellationToken cancellationToken = default, int? millisecondsTimeout = null, bool throwExceptionIfResponseNotReceived = true)

Parameters

command GetBrowserContextsCommandSettings
cancellationToken CancellationToken
millisecondsTimeout int?
throwExceptionIfResponseNotReceived bool

Returns

Task<GetBrowserContextsCommandResponse>

GetDevToolsTarget(GetDevToolsTargetCommandSettings, CancellationToken, int?, bool)

Gets the targetId of the DevTools page target opened for the given target (if any).

public Task<GetDevToolsTargetCommandResponse> GetDevToolsTarget(GetDevToolsTargetCommandSettings command, CancellationToken cancellationToken = default, int? millisecondsTimeout = null, bool throwExceptionIfResponseNotReceived = true)

Parameters

command GetDevToolsTargetCommandSettings
cancellationToken CancellationToken
millisecondsTimeout int?
throwExceptionIfResponseNotReceived bool

Returns

Task<GetDevToolsTargetCommandResponse>

GetTargetInfo(GetTargetInfoCommandSettings, CancellationToken, int?, bool)

Returns information about a target.

public Task<GetTargetInfoCommandResponse> GetTargetInfo(GetTargetInfoCommandSettings command, CancellationToken cancellationToken = default, int? millisecondsTimeout = null, bool throwExceptionIfResponseNotReceived = true)

Parameters

command GetTargetInfoCommandSettings
cancellationToken CancellationToken
millisecondsTimeout int?
throwExceptionIfResponseNotReceived bool

Returns

Task<GetTargetInfoCommandResponse>

GetTargets(GetTargetsCommandSettings, CancellationToken, int?, bool)

Retrieves a list of available targets.

public Task<GetTargetsCommandResponse> GetTargets(GetTargetsCommandSettings command, CancellationToken cancellationToken = default, int? millisecondsTimeout = null, bool throwExceptionIfResponseNotReceived = true)

Parameters

command GetTargetsCommandSettings
cancellationToken CancellationToken
millisecondsTimeout int?
throwExceptionIfResponseNotReceived bool

Returns

Task<GetTargetsCommandResponse>

OpenDevTools(OpenDevToolsCommandSettings, CancellationToken, int?, bool)

Opens a DevTools window for the target.

public Task<OpenDevToolsCommandResponse> OpenDevTools(OpenDevToolsCommandSettings command, CancellationToken cancellationToken = default, int? millisecondsTimeout = null, bool throwExceptionIfResponseNotReceived = true)

Parameters

command OpenDevToolsCommandSettings
cancellationToken CancellationToken
millisecondsTimeout int?
throwExceptionIfResponseNotReceived bool

Returns

Task<OpenDevToolsCommandResponse>

SendMessageToTarget(SendMessageToTargetCommandSettings, CancellationToken, int?, bool)

Sends protocol message over session with given id. Consider using flat mode instead; see commands attachToTarget, setAutoAttach, and crbug.com/991325.

public Task<SendMessageToTargetCommandResponse?> SendMessageToTarget(SendMessageToTargetCommandSettings command, CancellationToken cancellationToken = default, int? millisecondsTimeout = null, bool throwExceptionIfResponseNotReceived = true)

Parameters

command SendMessageToTargetCommandSettings
cancellationToken CancellationToken
millisecondsTimeout int?
throwExceptionIfResponseNotReceived bool

Returns

Task<SendMessageToTargetCommandResponse>

SetAutoAttach(SetAutoAttachCommandSettings, CancellationToken, int?, bool)

Controls whether to automatically attach to new targets which are considered to be directly related to this one (for example, iframes or workers). When turned on, attaches to all existing related targets as well. When turned off, automatically detaches from all currently attached targets. This also clears all targets added by autoAttachRelated from the list of targets to watch for creation of related targets. You might want to call this recursively for auto-attached targets to attach to all available targets.

public Task<SetAutoAttachCommandResponse?> SetAutoAttach(SetAutoAttachCommandSettings command, CancellationToken cancellationToken = default, int? millisecondsTimeout = null, bool throwExceptionIfResponseNotReceived = true)

Parameters

command SetAutoAttachCommandSettings
cancellationToken CancellationToken
millisecondsTimeout int?
throwExceptionIfResponseNotReceived bool

Returns

Task<SetAutoAttachCommandResponse>

SetDiscoverTargets(SetDiscoverTargetsCommandSettings, CancellationToken, int?, bool)

Controls whether to discover available targets and notify via targetCreated/targetInfoChanged/targetDestroyed events.

public Task<SetDiscoverTargetsCommandResponse?> SetDiscoverTargets(SetDiscoverTargetsCommandSettings command, CancellationToken cancellationToken = default, int? millisecondsTimeout = null, bool throwExceptionIfResponseNotReceived = true)

Parameters

command SetDiscoverTargetsCommandSettings
cancellationToken CancellationToken
millisecondsTimeout int?
throwExceptionIfResponseNotReceived bool

Returns

Task<SetDiscoverTargetsCommandResponse>

SetRemoteLocations(SetRemoteLocationsCommandSettings, CancellationToken, int?, bool)

Enables target discovery for the specified locations, when setDiscoverTargets was set to true.

public Task<SetRemoteLocationsCommandResponse?> SetRemoteLocations(SetRemoteLocationsCommandSettings command, CancellationToken cancellationToken = default, int? millisecondsTimeout = null, bool throwExceptionIfResponseNotReceived = true)

Parameters

command SetRemoteLocationsCommandSettings
cancellationToken CancellationToken
millisecondsTimeout int?
throwExceptionIfResponseNotReceived bool

Returns

Task<SetRemoteLocationsCommandResponse>

Events

AttachedToTarget

Issued when attached to target because of auto-attach or attachToTarget command.

public event EventHandler<AttachedToTargetEventArgs>? AttachedToTarget

Event Type

EventHandler<AttachedToTargetEventArgs>

DetachedFromTarget

Issued when detached from target for any reason (including detachFromTarget command). Can be issued multiple times per target if multiple sessions have been attached to it.

public event EventHandler<DetachedFromTargetEventArgs>? DetachedFromTarget

Event Type

EventHandler<DetachedFromTargetEventArgs>

ReceivedMessageFromTarget

Notifies about a new protocol message received from the session (as reported in attachedToTarget event).

public event EventHandler<ReceivedMessageFromTargetEventArgs>? ReceivedMessageFromTarget

Event Type

EventHandler<ReceivedMessageFromTargetEventArgs>

TargetCrashed

Issued when a target has crashed.

public event EventHandler<TargetCrashedEventArgs>? TargetCrashed

Event Type

EventHandler<TargetCrashedEventArgs>

TargetCreated

Issued when a possible inspection target is created.

public event EventHandler<TargetCreatedEventArgs>? TargetCreated

Event Type

EventHandler<TargetCreatedEventArgs>

TargetDestroyed

Issued when a target is destroyed.

public event EventHandler<TargetDestroyedEventArgs>? TargetDestroyed

Event Type

EventHandler<TargetDestroyedEventArgs>

TargetInfoChanged

Issued when some information about a target has changed. This only happens between targetCreated and targetDestroyed.

public event EventHandler<TargetInfoChangedEventArgs>? TargetInfoChanged

Event Type

EventHandler<TargetInfoChangedEventArgs>