PageInput Class

Plays the user of the page: the mouse, the keyboard and the touch screen. The input is dispatched as trusted events with the default actions of a browser (focus, text input, clicks, form submission, scrolling, drag and drop); the pointer targets the element under the pointer (hit testing), so an element covered by another one does not get the clicks. As in Playwright, each action first waits until the element is actionable (attached, visible, stable, enabled, editable, not covered, depending on the action), then waits until the page is idle.

public sealed class PageInput

Properties

NameDescription
RawGets the user input of WebPlatform, to send low-level input. Call TestPage.WaitForIdleAsync afterwards.

Gets the user input of WebPlatform, to send low-level input. Call TestPage.WaitForIdleAsync afterwards.

public UserInput Raw { get; }

Property value

UserInput

Methods

NameDescription
CheckAsync(Element, CancellationToken)Checks a check box or a radio button with a click, when it is not checked.
ClearAsync(Element, CancellationToken)Clears the value of a text field, then leaves the field.
ClickAsync(Element, ClickOptions?, CancellationToken)Clicks an element at its center (or at ClickOptions.Position), once it is visible, stable, enabled and not covered by another element.
ClickAsync(double, double, ClickOptions?, CancellationToken)Clicks a position of the viewport, in CSS pixels.
DoubleClickAsync(Element, CancellationToken)Double-clicks an element.
DragAndDropAsync(Element, Element, CancellationToken)Drags an element with the mouse, and drops it on another element (the HTML drag and drop events).
FillAsync(Element, string, CancellationToken)Replaces the value of a text field with a text typed with the keyboard, then leaves the field (the change event, so @bind updates the value). Waits until the field is visible, enabled and editable. An element of a label fills the control of the label.
FocusAsync(Element, CancellationToken)Focuses an element.
HoverAsync(Element, CancellationToken)Moves the mouse over an element, once it is visible, stable and not covered by another element.
PressAsync(string, string[])Presses a key while modifier keys are held (PressAsync("a", "Control")).
PressAsync(string, CancellationToken)Presses and releases a key in the focused element (a character or a key name such as Enter, Tab, ArrowDown).
RightClickAsync(Element, CancellationToken)Clicks an element with the secondary button (the contextmenu event).
SelectOptionAsync(Element, string[])Selects options of a select element by value or by label, and fires the input and change events. Waits until the element is visible and enabled, and until it has all the options.
SwipeAsync(Element, double, double, int, CancellationToken)Swipes from the center of an element with a finger: a moving touch scrolls the page and fires the touch events.
TapAsync(Element, CancellationToken)Taps an element with a finger (pointer, touch and mouse compatibility events, then click).
TypeAsync(Element, string, CancellationToken)Focuses an element, and types a text with the keyboard (the text is appended to the value of a field).
TypeAsync(string, CancellationToken)Types a text with the keyboard in the focused element.
UncheckAsync(Element, CancellationToken)Unchecks a check box with a click, when it is checked.
WheelAsync(Element, double, double, CancellationToken)Turns the mouse wheel over an element.

CheckAsync(Element, CancellationToken)

PageInput.cs

Checks a check box or a radio button with a click, when it is not checked.

public Task CheckAsync(Element element, CancellationToken cancellationToken = default)

Parameters

element Element
The element.
cancellationToken CancellationToken
A token to cancel the wait.

Returns

Task A task completed once the page is idle.

Exceptions

ElementNotInteractableException
The element is not a check box or a radio button, or the click does not check it.

ClearAsync(Element, CancellationToken)

PageInput.cs

Clears the value of a text field, then leaves the field.

public Task ClearAsync(Element element, CancellationToken cancellationToken = default)

Parameters

element Element
The text field.
cancellationToken CancellationToken
A token to cancel the wait.

Returns

Task A task completed once the page is idle.

ClickAsync overloads

ClickAsync(Element, ClickOptions?, CancellationToken)

PageInput.cs

Clicks an element at its center (or at ClickOptions.Position), once it is visible, stable, enabled and not covered by another element.

public Task ClickAsync(Element element, ClickOptions? options = null, CancellationToken cancellationToken = default)
Parameters
element Element
The element.
options ClickOptions?
The options, or null for the default options.
cancellationToken CancellationToken
A token to cancel the wait.
Returns

Task A task completed once the page is idle.

ClickAsync(double, double, ClickOptions?, CancellationToken)

PageInput.cs

Clicks a position of the viewport, in CSS pixels.

public Task ClickAsync(double x, double y, ClickOptions? options = null, CancellationToken cancellationToken = default)
Parameters
x double
The horizontal position.
y double
The vertical position.
options ClickOptions?
The options, or null for the default options.
cancellationToken CancellationToken
A token to cancel the wait.
Returns

Task A task completed once the page is idle.

DoubleClickAsync(Element, CancellationToken)

PageInput.cs

Double-clicks an element.

public Task DoubleClickAsync(Element element, CancellationToken cancellationToken = default)

Parameters

element Element
The element.
cancellationToken CancellationToken
A token to cancel the wait.

Returns

Task A task completed once the page is idle.

DragAndDropAsync(Element, Element, CancellationToken)

PageInput.cs

Drags an element with the mouse, and drops it on another element (the HTML drag and drop events).

public Task DragAndDropAsync(Element source, Element target, CancellationToken cancellationToken = default)

Parameters

source Element
The dragged element.
target Element
The element where the source is dropped.
cancellationToken CancellationToken
A token to cancel the wait.

Returns

Task A task completed once the page is idle.

FillAsync(Element, string, CancellationToken)

PageInput.cs

Replaces the value of a text field with a text typed with the keyboard, then leaves the field (the change event, so @bind updates the value). Waits until the field is visible, enabled and editable. An element of a label fills the control of the label.

public Task FillAsync(Element element, string text, CancellationToken cancellationToken = default)

Parameters

element Element
The text field (input, textarea or contenteditable element).
text string
The text.
cancellationToken CancellationToken
A token to cancel the wait.

Returns

Task A task completed once the page is idle.

Exceptions

ElementNotInteractableException
The element is not a text field.

FocusAsync(Element, CancellationToken)

PageInput.cs

Focuses an element.

public Task FocusAsync(Element element, CancellationToken cancellationToken = default)

Parameters

element Element
The element.
cancellationToken CancellationToken
A token to cancel the wait.

Returns

Task A task completed once the page is idle.

HoverAsync(Element, CancellationToken)

PageInput.cs

Moves the mouse over an element, once it is visible, stable and not covered by another element.

public Task HoverAsync(Element element, CancellationToken cancellationToken = default)

Parameters

element Element
The element.
cancellationToken CancellationToken
A token to cancel the wait.

Returns

Task A task completed once the page is idle.

PressAsync overloads

PressAsync(string, string[])

PageInput.cs

Presses a key while modifier keys are held (PressAsync("a", "Control")).

public Task PressAsync(string key, params string[] modifiers)
Parameters
key string
The key.
modifiers string[]
The modifier keys (Shift, Control, Alt, Meta).
Returns

Task A task completed once the page is idle.

PressAsync(string, CancellationToken)

PageInput.cs

Presses and releases a key in the focused element (a character or a key name such as Enter, Tab, ArrowDown).

public Task PressAsync(string key, CancellationToken cancellationToken = default)
Parameters
key string
The key.
cancellationToken CancellationToken
A token to cancel the wait.
Returns

Task A task completed once the page is idle.

RightClickAsync(Element, CancellationToken)

PageInput.cs

Clicks an element with the secondary button (the contextmenu event).

public Task RightClickAsync(Element element, CancellationToken cancellationToken = default)

Parameters

element Element
The element.
cancellationToken CancellationToken
A token to cancel the wait.

Returns

Task A task completed once the page is idle.

SelectOptionAsync(Element, string[])

PageInput.cs

Selects options of a select element by value or by label, and fires the input and change events. Waits until the element is visible and enabled, and until it has all the options.

public Task SelectOptionAsync(Element element, params string[] values)

Parameters

element Element
The select element.
values string[]
The values or the labels of the options to select.

Returns

Task A task completed once the page is idle.

SwipeAsync(Element, double, double, int, CancellationToken)

PageInput.cs

Swipes from the center of an element with a finger: a moving touch scrolls the page and fires the touch events.

net10.0

public Task SwipeAsync(Element element, double deltaX, double deltaY, int steps = 10, CancellationToken cancellationToken = default)

net11.0

public Task SwipeAsync(Element element, double deltaX, double deltaY, int steps = 10, CancellationToken cancellationToken = default)

Parameters

element Element
The element where the swipe starts.
deltaX double
The horizontal distance, in CSS pixels.
deltaY double
The vertical distance, in CSS pixels.
steps int
The number of moves.
cancellationToken CancellationToken
A token to cancel the wait.

Returns

Task A task completed once the page is idle.

TapAsync(Element, CancellationToken)

PageInput.cs

Taps an element with a finger (pointer, touch and mouse compatibility events, then click).

public Task TapAsync(Element element, CancellationToken cancellationToken = default)

Parameters

element Element
The element.
cancellationToken CancellationToken
A token to cancel the wait.

Returns

Task A task completed once the page is idle.

TypeAsync overloads

TypeAsync(Element, string, CancellationToken)

PageInput.cs

Focuses an element, and types a text with the keyboard (the text is appended to the value of a field).

public Task TypeAsync(Element element, string text, CancellationToken cancellationToken = default)
Parameters
element Element
The element.
text string
The text.
cancellationToken CancellationToken
A token to cancel the wait.
Returns

Task A task completed once the page is idle.

TypeAsync(string, CancellationToken)

PageInput.cs

Types a text with the keyboard in the focused element.

public Task TypeAsync(string text, CancellationToken cancellationToken = default)
Parameters
text string
The text.
cancellationToken CancellationToken
A token to cancel the wait.
Returns

Task A task completed once the page is idle.

UncheckAsync(Element, CancellationToken)

PageInput.cs

Unchecks a check box with a click, when it is checked.

public Task UncheckAsync(Element element, CancellationToken cancellationToken = default)

Parameters

element Element
The element.
cancellationToken CancellationToken
A token to cancel the wait.

Returns

Task A task completed once the page is idle.

Exceptions

ElementNotInteractableException
The element is not a check box, or the click does not uncheck it.

WheelAsync(Element, double, double, CancellationToken)

PageInput.cs

Turns the mouse wheel over an element.

net10.0

public Task WheelAsync(Element element, double deltaX, double deltaY, CancellationToken cancellationToken = default)

net11.0

public Task WheelAsync(Element element, double deltaX, double deltaY, CancellationToken cancellationToken = default)

Parameters

element Element
The element.
deltaX double
The horizontal delta, in CSS pixels.
deltaY double
The vertical delta, in CSS pixels.
cancellationToken CancellationToken
A token to cancel the wait.

Returns

Task A task completed once the page is idle.