ILocator Interface#
Represents a way to find elements on a page. Locators are strict by default and will throw if multiple elements match.
public interface ILocator
Properties#
First Property#
Returns a locator for the first matching element.
Motus.Abstractions.ILocator First { get; }
Property Value#
Last Property#
Returns a locator for the last matching element.
Motus.Abstractions.ILocator Last { get; }
Property Value#
Methods#
AllInnerTextsAsync() Method#
Returns all inner texts of matching elements.
System.Threading.Tasks.Task<System.Collections.Generic.IReadOnlyList<string>> AllInnerTextsAsync();
Returns#
System.Threading.Tasks.Task<System.Collections.Generic.IReadOnlyList<System.String>>
A list of inner text values.
AllTextContentsAsync() Method#
Returns all text contents of matching elements.
System.Threading.Tasks.Task<System.Collections.Generic.IReadOnlyList<string>> AllTextContentsAsync();
Returns#
System.Threading.Tasks.Task<System.Collections.Generic.IReadOnlyList<System.String>>
A list of text content values.
BoundingBoxAsync(Nullable<double>) Method#
Returns the bounding box of the element.
System.Threading.Tasks.Task<Motus.Abstractions.BoundingBox?> BoundingBoxAsync(System.Nullable<double> timeout=null);
Parameters#
timeout System.Nullable<System.Double>
Maximum time in milliseconds to wait.
Returns#
System.Threading.Tasks.Task<BoundingBox>
The bounding box, or null if the element is not visible.
CheckAsync(Nullable<double>) Method#
Checks the element (checkbox or radio button).
System.Threading.Tasks.Task CheckAsync(System.Nullable<double> timeout=null);
Parameters#
timeout System.Nullable<System.Double>
Maximum time in milliseconds to wait.
Returns#
ClearAsync(Nullable<double>) Method#
Clears the input field.
System.Threading.Tasks.Task ClearAsync(System.Nullable<double> timeout=null);
Parameters#
timeout System.Nullable<System.Double>
Maximum time in milliseconds to wait.
Returns#
ClickAsync(MouseButtonOptions, Nullable<double>) Method#
Clicks the element with a specific mouse button, or with modifier keys held.
System.Threading.Tasks.Task ClickAsync(Motus.Abstractions.MouseButtonOptions options, System.Nullable<double> timeout=null);
Parameters#
options MouseButtonOptions
The button to press, and the modifier keys the page sees held.
timeout System.Nullable<System.Double>
Maximum time in milliseconds to wait.
Returns#
Remarks#
This runs the same actionability checks as ClickAsync(Nullable<double>): the element has to be visible, enabled, settled, and receiving events before the button goes down. Assembling the same click from a bounding box and ClickAsync(double, double, MouseButtonOptions) skips every one of them, which is why a right-click or a modified click belongs here rather than at the caller.
ClickAsync(Nullable<double>) Method#
Clicks the element.
System.Threading.Tasks.Task ClickAsync(System.Nullable<double> timeout=null);
Parameters#
timeout System.Nullable<System.Double>
Maximum time in milliseconds to wait.
Returns#
CountAsync() Method#
Returns the number of elements matching the locator.
System.Threading.Tasks.Task<int> CountAsync();
Returns#
System.Threading.Tasks.Task<System.Int32>
The count of matching elements.
DblClickAsync(Nullable<double>) Method#
Double-clicks the element.
System.Threading.Tasks.Task DblClickAsync(System.Nullable<double> timeout=null);
Parameters#
timeout System.Nullable<System.Double>
Maximum time in milliseconds to wait.
Returns#
DispatchEventAsync(string, object) Method#
Dispatches an event on the element.
System.Threading.Tasks.Task DispatchEventAsync(string type, object? eventInit=null);
Parameters#
type System.String
The event type (e.g. "click").
eventInit System.Object
Optional event initialization properties.
Returns#
ElementHandleAsync(Nullable<double>) Method#
Resolves the locator to the first matching DOM element handle.
System.Threading.Tasks.Task<Motus.Abstractions.IElementHandle> ElementHandleAsync(System.Nullable<double> timeout=null);
Parameters#
timeout System.Nullable<System.Double>
Maximum time in milliseconds to wait.
Returns#
System.Threading.Tasks.Task<IElementHandle>
The element handle.
ElementHandlesAsync() Method#
Resolves the locator to all matching DOM element handles.
System.Threading.Tasks.Task<System.Collections.Generic.IReadOnlyList<Motus.Abstractions.IElementHandle>> ElementHandlesAsync();
Returns#
System.Threading.Tasks.Task<System.Collections.Generic.IReadOnlyList<IElementHandle>>
A list of element handles.
EvaluateAsync<T>(string, object) Method#
Evaluates a JavaScript expression with the matching element bound as this. Use a
function() { ... this ... } literal to access the element. Arrow functions cannot use
this as the element; for arrow-style el => el.foo, use
EvaluateWithElementAsync<T>(string, object) instead.
System.Threading.Tasks.Task<T> EvaluateAsync<T>(string expression, object? arg=null);
Type parameters#
T
The expected return type.
Parameters#
expression System.String
A function literal whose this is the element.
arg System.Object
Optional argument passed as the function's first parameter.
Returns#
System.Threading.Tasks.Task<T>
The result of the evaluation.
EvaluateWithElementAsync<T>(string, object) Method#
Evaluates a JavaScript expression with the matching element passed as the first argument to
the function. Matches the Playwright convention: el => el.foo receives the element
as el. When arg is supplied it becomes the function's second argument.
System.Threading.Tasks.Task<T> EvaluateWithElementAsync<T>(string pageFunction, object? arg=null);
Type parameters#
T
The expected return type.
Parameters#
pageFunction System.String
An arrow or function literal that accepts the element as its first parameter.
arg System.Object
Optional value passed as the function's second parameter.
Returns#
System.Threading.Tasks.Task<T>
The result of the evaluation.
FillAsync(string, Nullable<double>) Method#
Fills the element with the specified text. Clears existing content first.
System.Threading.Tasks.Task FillAsync(string value, System.Nullable<double> timeout=null);
Parameters#
value System.String
The text to fill.
timeout System.Nullable<System.Double>
Maximum time in milliseconds to wait.
Returns#
Filter(LocatorOptions) Method#
Filters the locator to match only elements satisfying the specified options.
Motus.Abstractions.ILocator Filter(Motus.Abstractions.LocatorOptions? options=null);
Parameters#
options LocatorOptions
Filter options.
Returns#
ILocator
A filtered locator.
FocusAsync(Nullable<double>) Method#
Focuses the element.
System.Threading.Tasks.Task FocusAsync(System.Nullable<double> timeout=null);
Parameters#
timeout System.Nullable<System.Double>
Maximum time in milliseconds to wait.
Returns#
GetAttributeAsync(string, Nullable<double>) Method#
Returns the value of the specified attribute.
System.Threading.Tasks.Task<string?> GetAttributeAsync(string name, System.Nullable<double> timeout=null);
Parameters#
name System.String
The attribute name.
timeout System.Nullable<System.Double>
Maximum time in milliseconds to wait.
Returns#
System.Threading.Tasks.Task<System.String>
The attribute value, or null.
HoverAsync(Nullable<double>) Method#
Hovers over the element.
System.Threading.Tasks.Task HoverAsync(System.Nullable<double> timeout=null);
Parameters#
timeout System.Nullable<System.Double>
Maximum time in milliseconds to wait.
Returns#
InnerHTMLAsync(Nullable<double>) Method#
Returns the inner HTML of the element.
System.Threading.Tasks.Task<string> InnerHTMLAsync(System.Nullable<double> timeout=null);
Parameters#
timeout System.Nullable<System.Double>
Maximum time in milliseconds to wait.
Returns#
System.Threading.Tasks.Task<System.String>
The inner HTML markup.
InnerTextAsync(Nullable<double>) Method#
Returns the inner text of the element.
System.Threading.Tasks.Task<string> InnerTextAsync(System.Nullable<double> timeout=null);
Parameters#
timeout System.Nullable<System.Double>
Maximum time in milliseconds to wait.
Returns#
System.Threading.Tasks.Task<System.String>
The inner text.
InputValueAsync(Nullable<double>) Method#
Returns the input value of the element.
System.Threading.Tasks.Task<string> InputValueAsync(System.Nullable<double> timeout=null);
Parameters#
timeout System.Nullable<System.Double>
Maximum time in milliseconds to wait.
Returns#
System.Threading.Tasks.Task<System.String>
The input value.
IsCheckedAsync(Nullable<double>) Method#
Returns whether the element is checked.
System.Threading.Tasks.Task<bool> IsCheckedAsync(System.Nullable<double> timeout=null);
Parameters#
timeout System.Nullable<System.Double>
Maximum time in milliseconds to wait.
Returns#
System.Threading.Tasks.Task<System.Boolean>
True if the element is checked.
IsDisabledAsync(Nullable<double>) Method#
Returns whether the element is disabled.
System.Threading.Tasks.Task<bool> IsDisabledAsync(System.Nullable<double> timeout=null);
Parameters#
timeout System.Nullable<System.Double>
Maximum time in milliseconds to wait.
Returns#
System.Threading.Tasks.Task<System.Boolean>
True if the element is disabled.
IsEditableAsync(Nullable<double>) Method#
Returns whether the element is editable.
System.Threading.Tasks.Task<bool> IsEditableAsync(System.Nullable<double> timeout=null);
Parameters#
timeout System.Nullable<System.Double>
Maximum time in milliseconds to wait.
Returns#
System.Threading.Tasks.Task<System.Boolean>
True if the element is editable.
IsEnabledAsync(Nullable<double>) Method#
Returns whether the element is enabled.
System.Threading.Tasks.Task<bool> IsEnabledAsync(System.Nullable<double> timeout=null);
Parameters#
timeout System.Nullable<System.Double>
Maximum time in milliseconds to wait.
Returns#
System.Threading.Tasks.Task<System.Boolean>
True if the element is enabled.
IsHiddenAsync(Nullable<double>) Method#
Returns whether the element is hidden.
System.Threading.Tasks.Task<bool> IsHiddenAsync(System.Nullable<double> timeout=null);
Parameters#
timeout System.Nullable<System.Double>
Maximum time in milliseconds to wait.
Returns#
System.Threading.Tasks.Task<System.Boolean>
True if the element is hidden.
IsVisibleAsync(Nullable<double>) Method#
Returns whether the element is visible.
System.Threading.Tasks.Task<bool> IsVisibleAsync(System.Nullable<double> timeout=null);
Parameters#
timeout System.Nullable<System.Double>
Maximum time in milliseconds to wait.
Returns#
System.Threading.Tasks.Task<System.Boolean>
True if the element is visible.
Locator(string, LocatorOptions) Method#
Creates a child locator scoped to the current locator, matching Playwright's semantics for
chained locators. Resolution first materializes the parent's element(s) from the DOM, then
runs querySelectorAll for the child selector under each parent and flattens the
results (deduped by identity, in parent-list order). Parents found via non-CSS strategies
such as xpath=, role=, text=, or data-testid= participate
normally because the parent handle is already resolved before the descendant query runs.
Pass ".." (or "../..", "../../..") as the selector to walk to an ancestor
via each base match's parentElement before any later descendant chain.
Motus.Abstractions.ILocator Locator(string selector, Motus.Abstractions.LocatorOptions? options=null);
Parameters#
selector System.String
The CSS selector for descendant elements, or a ".."/"../.." chain to navigate to ancestors.
options LocatorOptions
Locator options. When supplied, fields override the parent's values.
Returns#
ILocator
A child locator.
Nth(int) Method#
Returns a locator for the nth matching element (zero-based).
Motus.Abstractions.ILocator Nth(int index);
Parameters#
index System.Int32
The zero-based index.
Returns#
ILocator
A locator for the nth element.
PressAsync(string, KeyboardPressOptions) Method#
Presses a key on the element.
System.Threading.Tasks.Task PressAsync(string key, Motus.Abstractions.KeyboardPressOptions? options=null);
Parameters#
key System.String
The key to press.
options KeyboardPressOptions
Press options.
Returns#
ScreenshotAsync(ScreenshotOptions) Method#
Takes a screenshot of the element.
System.Threading.Tasks.Task<byte[]> ScreenshotAsync(Motus.Abstractions.ScreenshotOptions? options=null);
Parameters#
options ScreenshotOptions
Screenshot options.
Returns#
System.Threading.Tasks.Task<System.Byte[]>
The screenshot as a byte array.
ScrollIntoViewIfNeededAsync(Nullable<double>) Method#
Scrolls the element into view.
System.Threading.Tasks.Task ScrollIntoViewIfNeededAsync(System.Nullable<double> timeout=null);
Parameters#
timeout System.Nullable<System.Double>
Maximum time in milliseconds to wait.
Returns#
SelectOptionAsync(string[]) Method#
Selects options in a select element by value.
System.Threading.Tasks.Task<System.Collections.Generic.IReadOnlyList<string>> SelectOptionAsync(params string[] values);
Parameters#
values System.String[]
The option values to select.
Returns#
System.Threading.Tasks.Task<System.Collections.Generic.IReadOnlyList<System.String>>
The selected option values.
SelectOptionAsync(string[], Nullable<double>) Method#
Selects options in a select element by value, waiting no longer than the given timeout.
System.Threading.Tasks.Task<System.Collections.Generic.IReadOnlyList<string>> SelectOptionAsync(string[] values, System.Nullable<double> timeout);
Parameters#
values System.String[]
The option values to select.
timeout System.Nullable<System.Double>
Maximum time in milliseconds to wait.
Returns#
System.Threading.Tasks.Task<System.Collections.Generic.IReadOnlyList<System.String>>
The selected option values.
Remarks#
The timeout has no default here, so a call that passes only values still binds to the
params overload above and means the same thing it always did.
SetCheckedAsync(bool, Nullable<double>) Method#
Sets the checked state of a checkbox or radio button.
System.Threading.Tasks.Task SetCheckedAsync(bool @checked, System.Nullable<double> timeout=null);
Parameters#
checked System.Boolean
Whether to check or uncheck the element.
timeout System.Nullable<System.Double>
Maximum time in milliseconds to wait.
Returns#
SetInputFilesAsync(IEnumerable<FilePayload>, Nullable<double>) Method#
Sets the files for a file input element.
System.Threading.Tasks.Task SetInputFilesAsync(System.Collections.Generic.IEnumerable<Motus.Abstractions.FilePayload> files, System.Nullable<double> timeout=null);
Parameters#
files System.Collections.Generic.IEnumerable<FilePayload>
The files to set.
timeout System.Nullable<System.Double>
Maximum time in milliseconds to wait.
Returns#
TapAsync(Nullable<double>) Method#
Taps the element (for touch-enabled devices).
System.Threading.Tasks.Task TapAsync(System.Nullable<double> timeout=null);
Parameters#
timeout System.Nullable<System.Double>
Maximum time in milliseconds to wait.
Returns#
TextContentAsync(Nullable<double>) Method#
Returns the text content of the element.
System.Threading.Tasks.Task<string?> TextContentAsync(System.Nullable<double> timeout=null);
Parameters#
timeout System.Nullable<System.Double>
Maximum time in milliseconds to wait.
Returns#
System.Threading.Tasks.Task<System.String>
The text content.
TypeAsync(string, KeyboardTypeOptions) Method#
Types text character by character into the element.
System.Threading.Tasks.Task TypeAsync(string text, Motus.Abstractions.KeyboardTypeOptions? options=null);
Parameters#
text System.String
The text to type.
options KeyboardTypeOptions
Typing options.
Returns#
UncheckAsync(Nullable<double>) Method#
Unchecks the element (checkbox).
System.Threading.Tasks.Task UncheckAsync(System.Nullable<double> timeout=null);
Parameters#
timeout System.Nullable<System.Double>
Maximum time in milliseconds to wait.
Returns#
WaitForAsync(Nullable<ElementState>, Nullable<double>) Method#
Waits for the element to satisfy the specified state.
System.Threading.Tasks.Task WaitForAsync(System.Nullable<Motus.Abstractions.ElementState> state=null, System.Nullable<double> timeout=null);
Parameters#
state System.Nullable<ElementState>
The desired element state.
timeout System.Nullable<System.Double>
Maximum time in milliseconds to wait.