Table of Contents

Class Locator

Namespace
PuppeteerSharp.Locators
Assembly
PuppeteerSharp.dll

Locators describe a strategy of locating elements and performing an action on them. If the action fails because the element is not ready for the action, the whole operation is retried. Various preconditions for a successful action are checked automatically.

public abstract class Locator
Inheritance
Locator

Properties

EnsureElementIsInTheViewport

Gets or sets a value indicating whether to ensure the element is in the viewport.

protected bool EnsureElementIsInTheViewport { get; set; }

Property Value

bool

Timeout

Gets or sets the timeout in milliseconds.

protected int Timeout { get; set; }

Property Value

int

Visibility

Gets or sets the visibility option.

protected VisibilityOption? Visibility { get; set; }

Property Value

VisibilityOption?

WaitForEnabled

Gets or sets a value indicating whether to wait for the element to be enabled.

protected bool WaitForEnabled { get; set; }

Property Value

bool

WaitForStableBoundingBox

Gets or sets a value indicating whether to wait for a stable bounding box.

protected bool WaitForStableBoundingBox { get; set; }

Property Value

bool

Methods

ClickAsync(LocatorClickOptions)

Clicks the located element.

public Task ClickAsync(LocatorClickOptions options = null)

Parameters

options LocatorClickOptions

Optional click options.

Returns

Task

A task that completes when the click is performed.

FillAsync(string, LocatorActionOptions)

Fills the located element with the provided value.

public Task FillAsync(string value, LocatorActionOptions options = null)

Parameters

value string

The value to fill.

options LocatorActionOptions

Optional action options.

Returns

Task

A task that completes when the fill is performed.

Filter(string)

Creates a new locator that filters elements using the provided predicate. If the predicate does not match, the locator will retry.

public Locator Filter(string predicate)

Parameters

predicate string

A JavaScript function expression that takes an element and returns a boolean.

Returns

Locator

A new locator that filters based on the predicate.

HoverAsync(LocatorActionOptions)

Hovers over the located element.

public Task HoverAsync(LocatorActionOptions options = null)

Parameters

options LocatorActionOptions

Optional action options.

Returns

Task

A task that completes when the hover is performed.

Map(string)

Maps the locator using the provided mapper.

public Locator Map(string mapper)

Parameters

mapper string

A JavaScript function expression that transforms the element.

Returns

Locator

A new locator that maps the element.

Race(params Locator[])

Creates a new locator that races multiple locators, returning the first one to resolve.

public static Locator Race(params Locator[] locators)

Parameters

locators Locator[]

The locators to race.

Returns

Locator

A new locator that resolves to the first matching locator's result.

ScrollAsync(LocatorScrollOptions)

Scrolls the located element.

public Task ScrollAsync(LocatorScrollOptions options = null)

Parameters

options LocatorScrollOptions

Optional scroll options.

Returns

Task

A task that completes when the scroll is performed.

SetEnsureElementIsInTheViewport(bool)

Sets whether to ensure the element is scrolled into the viewport.

public Locator SetEnsureElementIsInTheViewport(bool value)

Parameters

value bool

Whether to ensure the element is in the viewport.

Returns

Locator

The locator instance for chaining.

SetTimeout(int)

Sets the timeout for the locator.

public Locator SetTimeout(int timeout)

Parameters

timeout int

Timeout in milliseconds.

Returns

Locator

The locator instance for chaining.

SetVisibility(VisibilityOption?)

Sets the visibility option for the locator.

public Locator SetVisibility(VisibilityOption? visibility)

Parameters

visibility VisibilityOption?

The visibility option.

Returns

Locator

The locator instance for chaining.

SetWaitForEnabled(bool)

Sets whether to wait for the element to be enabled before acting.

public Locator SetWaitForEnabled(bool value)

Parameters

value bool

Whether to wait for enabled.

Returns

Locator

The locator instance for chaining.

SetWaitForStableBoundingBox(bool)

Sets whether to wait for a stable bounding box before acting.

public Locator SetWaitForStableBoundingBox(bool value)

Parameters

value bool

Whether to wait for a stable bounding box.

Returns

Locator

The locator instance for chaining.

WaitAsync(LocatorActionOptions)

Waits for the locator to locate an element.

public Task WaitAsync(LocatorActionOptions options = null)

Parameters

options LocatorActionOptions

Optional action options.

Returns

Task

A task that completes when the element is located.

WaitAsync<T>(LocatorActionOptions)

Waits for the locator to get a value from the page. Note this requires the value to be JSON-serializable.

public Task<T> WaitAsync<T>(LocatorActionOptions options = null)

Parameters

options LocatorActionOptions

Optional action options.

Returns

Task<T>

A task that resolves to the serialized value.

Type Parameters

T

The type of the return value.

WaitHandleAsync(LocatorActionOptions)

Waits for the locator to get a handle from the page.

public Task<IJSHandle> WaitHandleAsync(LocatorActionOptions options = null)

Parameters

options LocatorActionOptions

Optional action options.

Returns

Task<IJSHandle>

A task that resolves to a handle for the located element.