IPage Interface#
Represents a single browser page (tab). Provides methods for navigation, interaction, evaluation, and more.
public interface IPage : System.IAsyncDisposable
Implements System.IAsyncDisposable
Properties#
Context Property#
Gets the browser context that owns this page.
Motus.Abstractions.IBrowserContext Context { get; }
Property Value#
Frames Property#
Gets all frames in the page, including the main frame, in the order they attached.
System.Collections.Generic.IReadOnlyList<Motus.Abstractions.IFrame> Frames { get; }
Property Value#
System.Collections.Generic.IReadOnlyList<IFrame>
Remarks#
For frames that share a parent, attach order is the order their elements appear in the page, unless the page inserted one later, in which case it goes on the end.
IsClosed Property#
Gets whether the page has been closed.
bool IsClosed { get; }
Property Value#
Keyboard Property#
Gets the keyboard input handler.
Motus.Abstractions.IKeyboard Keyboard { get; }
Property Value#
MainFrame Property#
Gets the main frame of the page.
Motus.Abstractions.IFrame MainFrame { get; }
Property Value#
Mouse Property#
Gets the mouse input handler.
Motus.Abstractions.IMouse Mouse { get; }
Property Value#
Touchscreen Property#
Gets the touchscreen input handler.
Motus.Abstractions.ITouchscreen Touchscreen { get; }
Property Value#
Url Property#
Gets the current URL of the page.
string Url { get; }
Property Value#
Video Property#
Gets the video recorder for this page, or null if video recording is not enabled.
Motus.Abstractions.IVideo? Video { get; }
Property Value#
ViewportSize Property#
Gets the viewport size, or null if no viewport is set.
Motus.Abstractions.ViewportSize? ViewportSize { get; }
Property Value#
Methods#
AccessibilitySnapshotAsync(CancellationToken) Method#
Fetches the page's accessibility tree. Each returned node carries its role, accessible name, properties, children, and (where available) a backend DOM node identifier that LocatorByBackendNodeId(long) can target.
System.Threading.Tasks.Task<Motus.Abstractions.AccessibilitySnapshot> AccessibilitySnapshotAsync(System.Threading.CancellationToken ct=default(System.Threading.CancellationToken));
Parameters#
ct System.Threading.CancellationToken
A token to cancel the operation.
Returns#
System.Threading.Tasks.Task<AccessibilitySnapshot>
A snapshot of the accessibility tree.
AddScriptTagAsync(string, string) Method#
Adds a script tag to the page.
System.Threading.Tasks.Task<Motus.Abstractions.IElementHandle> AddScriptTagAsync(string? url=null, string? content=null);
Parameters#
url System.String
URL of the script to add.
content System.String
Inline script content.
Returns#
System.Threading.Tasks.Task<IElementHandle>
An element handle to the script element.
AddStyleTagAsync(string, string) Method#
Adds a style tag to the page.
System.Threading.Tasks.Task<Motus.Abstractions.IElementHandle> AddStyleTagAsync(string? url=null, string? content=null);
Parameters#
url System.String
URL of the stylesheet to add.
content System.String
Inline CSS content.
Returns#
System.Threading.Tasks.Task<IElementHandle>
An element handle to the style element.
BringToFrontAsync() Method#
Brings the page to the front (activates the tab).
System.Threading.Tasks.Task BringToFrontAsync();
Returns#
CloseAsync(Nullable<bool>) Method#
Closes the page.
System.Threading.Tasks.Task CloseAsync(System.Nullable<bool> runBeforeUnload=null);
Parameters#
runBeforeUnload System.Nullable<System.Boolean>
Whether to run the beforeunload handler.
Returns#
ContentAsync() Method#
Returns the full HTML content of the page.
System.Threading.Tasks.Task<string> ContentAsync();
Returns#
System.Threading.Tasks.Task<System.String>
The HTML content.
EmulateMediaAsync(string, Nullable<ColorScheme>) Method#
Emulates the given media type or features.
System.Threading.Tasks.Task EmulateMediaAsync(string? media=null, System.Nullable<Motus.Abstractions.ColorScheme> colorScheme=null);
Parameters#
media System.String
The media type (e.g. "screen", "print").
colorScheme System.Nullable<ColorScheme>
The color scheme to emulate.
Returns#
EvaluateAsync<T>(string, object) Method#
Evaluates a JavaScript expression in the page context.
System.Threading.Tasks.Task<T> EvaluateAsync<T>(string expression, object? arg=null);
Type parameters#
T
The expected return type.
Parameters#
expression System.String
The JavaScript expression to evaluate.
arg System.Object
Optional argument to pass to the expression.
Returns#
System.Threading.Tasks.Task<T>
The result of the evaluation.
EvaluateHandleAsync(string, object) Method#
Evaluates a JavaScript expression and returns a handle to the result.
System.Threading.Tasks.Task<Motus.Abstractions.IJSHandle> EvaluateHandleAsync(string expression, object? arg=null);
Parameters#
expression System.String
The JavaScript expression to evaluate.
arg System.Object
Optional argument to pass to the expression.
Returns#
System.Threading.Tasks.Task<IJSHandle>
A handle to the result.
ExposeBindingAsync(string, Func<object[],Task<object>>) Method#
Exposes a .NET function to be called from JavaScript.
System.Threading.Tasks.Task ExposeBindingAsync(string name, System.Func<object?[],System.Threading.Tasks.Task<object?>> callback);
Parameters#
name System.String
The function name to expose in the page.
callback System.Func<System.Object[],System.Threading.Tasks.Task<System.Object>>
The callback to invoke.
Returns#
GetByAltText(string, Nullable<bool>) Method#
Creates a locator for the element matching the specified alt text.
Motus.Abstractions.ILocator GetByAltText(string text, System.Nullable<bool> exact=null);
Parameters#
text System.String
The alt text to match.
exact System.Nullable<System.Boolean>
Whether to match the text exactly.
Returns#
ILocator
A locator for the matching elements.
GetByLabel(string, Nullable<bool>) Method#
Creates a locator for the element matching the specified label.
Motus.Abstractions.ILocator GetByLabel(string text, System.Nullable<bool> exact=null);
Parameters#
text System.String
The label text to match.
exact System.Nullable<System.Boolean>
Whether to match the text exactly.
Returns#
ILocator
A locator for the matching elements.
GetByPlaceholder(string, Nullable<bool>) Method#
Creates a locator for the element matching the specified placeholder.
Motus.Abstractions.ILocator GetByPlaceholder(string text, System.Nullable<bool> exact=null);
Parameters#
text System.String
The placeholder text to match.
exact System.Nullable<System.Boolean>
Whether to match the text exactly.
Returns#
ILocator
A locator for the matching elements.
GetByRole(string, string) Method#
Creates a locator for the element matching the specified role.
Motus.Abstractions.ILocator GetByRole(string role, string? name=null);
Parameters#
role System.String
The ARIA role to match.
name System.String
Optional accessible name to filter by.
Returns#
ILocator
A locator for the matching elements.
Remarks#
Role matching runs over the accessibility tree, which spans the page's frames. This is the one page-level locator that can match an element inside a frame; the others are confined to the main document. Use GetByRole(string, string) to confine a role match to one frame.
GetByTestId(string) Method#
Creates a locator for the element matching the specified test ID.
Motus.Abstractions.ILocator GetByTestId(string testId);
Parameters#
testId System.String
The test ID to match.
Returns#
ILocator
A locator for the matching elements.
GetByText(string, Nullable<bool>) Method#
Creates a locator for the element matching the specified text.
Motus.Abstractions.ILocator GetByText(string text, System.Nullable<bool> exact=null);
Parameters#
text System.String
The text to match.
exact System.Nullable<System.Boolean>
Whether to match the text exactly.
Returns#
ILocator
A locator for the matching elements.
GetByTitle(string, Nullable<bool>) Method#
Creates a locator for the element matching the specified title.
Motus.Abstractions.ILocator GetByTitle(string text, System.Nullable<bool> exact=null);
Parameters#
text System.String
The title text to match.
exact System.Nullable<System.Boolean>
Whether to match the text exactly.
Returns#
ILocator
A locator for the matching elements.
GetPerformanceMetricsAsync(CancellationToken) Method#
Returns the page's performance metrics: Core Web Vitals (LCP, FCP, CLS, INP) along with TTFB, JS heap size, and DOM node count. The metrics reflect the most recent navigation, with the latest Core Web Vitals re-read on each call so values that settle after load are picked up. Returns null when no metrics have been collected yet.
System.Threading.Tasks.Task<Motus.Abstractions.PerformanceMetrics?> GetPerformanceMetricsAsync(System.Threading.CancellationToken ct=default(System.Threading.CancellationToken));
Parameters#
ct System.Threading.CancellationToken
A token to cancel the operation.
Returns#
System.Threading.Tasks.Task<PerformanceMetrics>
The current performance metrics, or null if none have been collected.
GoBackAsync(NavigationOptions) Method#
Navigates back in the page history.
System.Threading.Tasks.Task<Motus.Abstractions.IResponse?> GoBackAsync(Motus.Abstractions.NavigationOptions? options=null);
Parameters#
options NavigationOptions
Navigation options.
Returns#
System.Threading.Tasks.Task<IResponse>
The response of the navigation, or null.
GoForwardAsync(NavigationOptions) Method#
Navigates forward in the page history.
System.Threading.Tasks.Task<Motus.Abstractions.IResponse?> GoForwardAsync(Motus.Abstractions.NavigationOptions? options=null);
Parameters#
options NavigationOptions
Navigation options.
Returns#
System.Threading.Tasks.Task<IResponse>
The response of the navigation, or null.
GotoAsync(string, NavigationOptions) Method#
Navigates the page to the specified URL.
System.Threading.Tasks.Task<Motus.Abstractions.IResponse?> GotoAsync(string url, Motus.Abstractions.NavigationOptions? options=null);
Parameters#
url System.String
The URL to navigate to.
options NavigationOptions
Navigation options.
Returns#
System.Threading.Tasks.Task<IResponse>
The response of the navigation, or null.
Locator(string, LocatorOptions) Method#
Creates a locator for the specified selector.
Motus.Abstractions.ILocator Locator(string selector, Motus.Abstractions.LocatorOptions? options=null);
Parameters#
selector System.String
The selector to locate elements.
options LocatorOptions
Locator options.
Returns#
ILocator
A locator for the matching elements.
LocatorByBackendNodeId(long) Method#
Creates a locator that targets a single element by its backend DOM node identifier, as reported on BackendDOMNodeId by AccessibilitySnapshotAsync(CancellationToken). The element is resolved when an action is first invoked on the locator; if the node is no longer attached to the document, the action fails.
Motus.Abstractions.ILocator LocatorByBackendNodeId(long backendNodeId);
Parameters#
backendNodeId System.Int64
The backend DOM node identifier to target.
Returns#
ILocator
A locator for the matching element.
PauseAsync() Method#
Pauses script execution. Useful for debugging.
System.Threading.Tasks.Task PauseAsync();
Returns#
PdfAsync(string) Method#
Generates a PDF of the page. Only supported in headless Chromium.
System.Threading.Tasks.Task<byte[]> PdfAsync(string? path=null);
Parameters#
path System.String
Optional path to save the PDF to.
Returns#
System.Threading.Tasks.Task<System.Byte[]>
The PDF as a byte array.
ReloadAsync(NavigationOptions) Method#
Reloads the current page.
System.Threading.Tasks.Task<Motus.Abstractions.IResponse?> ReloadAsync(Motus.Abstractions.NavigationOptions? options=null);
Parameters#
options NavigationOptions
Navigation options.
Returns#
System.Threading.Tasks.Task<IResponse>
The response of the reload, or null.
RouteAsync(string, Func<IRoute,Task>) Method#
Registers a route handler for requests matching the URL pattern.
System.Threading.Tasks.Task RouteAsync(string urlPattern, System.Func<Motus.Abstractions.IRoute,System.Threading.Tasks.Task> handler);
Parameters#
urlPattern System.String
The URL pattern to match.
handler System.Func<IRoute,System.Threading.Tasks.Task>
The route handler.
Returns#
RunAccessibilityAuditAsync(CancellationToken) Method#
Runs the built-in WCAG accessibility rules against the page's accessibility tree and returns the violations found. Each violation carries a rule id, severity, message, and, where the offending element is addressable, the backend DOM node identifier that LocatorByBackendNodeId(long) can target.
System.Threading.Tasks.Task<Motus.Abstractions.AccessibilityAuditResult> RunAccessibilityAuditAsync(System.Threading.CancellationToken ct=default(System.Threading.CancellationToken));
Parameters#
ct System.Threading.CancellationToken
A token to cancel the operation.
Returns#
System.Threading.Tasks.Task<AccessibilityAuditResult>
The audit result, including the violations and pass count.
ScreenshotAsync(ScreenshotOptions) Method#
Takes a screenshot of the page.
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.
SetContentAsync(string, NavigationOptions) Method#
Sets the HTML content of the page.
System.Threading.Tasks.Task SetContentAsync(string html, Motus.Abstractions.NavigationOptions? options=null);
Parameters#
html System.String
The HTML content to set.
options NavigationOptions
Navigation options.
Returns#
SetViewportSizeAsync(ViewportSize) Method#
Sets the viewport size.
System.Threading.Tasks.Task SetViewportSizeAsync(Motus.Abstractions.ViewportSize viewportSize);
Parameters#
viewportSize ViewportSize
The new viewport size.
Returns#
StartHarRecordingAsync(CancellationToken) Method#
Begins recording this page's network traffic as an HTTP archive. Requests and responses that occur after this call are captured until StopHarRecordingAsync(string, CancellationToken) writes them out. Calling this while a recording is already in progress has no effect.
System.Threading.Tasks.Task StartHarRecordingAsync(System.Threading.CancellationToken ct=default(System.Threading.CancellationToken));
Parameters#
ct System.Threading.CancellationToken
A token to cancel the operation.
Returns#
StartVideoRecordingAsync(string, ViewportSize, CancellationToken) Method#
Begins recording this page to a video file (MJPEG in an AVI container, captured via the browser's screencast, which paces frames by screen updates and shows no pointer cursor). Throws if a recording is already in progress, including one started by the context's RecordVideo option.
System.Threading.Tasks.Task<string> StartVideoRecordingAsync(string? path=null, Motus.Abstractions.ViewportSize? size=null, System.Threading.CancellationToken ct=default(System.Threading.CancellationToken));
Parameters#
path System.String
The output file path; when null, a file is created under the system temp directory.
size ViewportSize
The capture resolution; when null, the page's viewport size is used.
ct System.Threading.CancellationToken
A token to cancel the operation.
Returns#
System.Threading.Tasks.Task<System.String>
The path the video is being written to.
StopHarRecordingAsync(string, CancellationToken) Method#
Stops the recording started by StartHarRecordingAsync(CancellationToken) and writes the captured traffic to path as an HTTP archive (HAR 1.2) file. Throws if no recording is in progress.
System.Threading.Tasks.Task StopHarRecordingAsync(string path, System.Threading.CancellationToken ct=default(System.Threading.CancellationToken));
Parameters#
path System.String
The file path to write the HAR archive to.
ct System.Threading.CancellationToken
A token to cancel the operation.
Returns#
StopVideoRecordingAsync(CancellationToken) Method#
Stops the recording started by StartVideoRecordingAsync(string, ViewportSize, CancellationToken) and finalizes the video file. Throws if no recording is in progress, or if the recording was started by the context's RecordVideo option (those span the page's life and finalize when it closes).
System.Threading.Tasks.Task<string> StopVideoRecordingAsync(System.Threading.CancellationToken ct=default(System.Threading.CancellationToken));
Parameters#
ct System.Threading.CancellationToken
A token to cancel the operation.
Returns#
System.Threading.Tasks.Task<System.String>
The path of the finalized video file.
TitleAsync() Method#
Returns the title of the page.
System.Threading.Tasks.Task<string> TitleAsync();
Returns#
System.Threading.Tasks.Task<System.String>
The page title.
UnrouteAsync(string, Func<IRoute,Task>) Method#
Removes a previously registered route handler.
System.Threading.Tasks.Task UnrouteAsync(string urlPattern, System.Func<Motus.Abstractions.IRoute,System.Threading.Tasks.Task>? handler=null);
Parameters#
urlPattern System.String
The URL pattern to unregister.
handler System.Func<IRoute,System.Threading.Tasks.Task>
The handler to remove. If null, removes all handlers for the pattern.
Returns#
WaitForFunctionAsync<T>(string, object, Nullable<double>) Method#
Waits for a function to return a truthy value.
System.Threading.Tasks.Task<T> WaitForFunctionAsync<T>(string expression, object? arg=null, System.Nullable<double> timeout=null);
Type parameters#
T
The expected return type.
Parameters#
expression System.String
The JavaScript expression to evaluate.
arg System.Object
Optional argument to pass to the expression.
timeout System.Nullable<System.Double>
Maximum time in milliseconds to wait.
Returns#
System.Threading.Tasks.Task<T>
The return value of the function.
WaitForLoadStateAsync(Nullable<LoadState>, Nullable<double>) Method#
Waits for the specified load state.
System.Threading.Tasks.Task WaitForLoadStateAsync(System.Nullable<Motus.Abstractions.LoadState> state=null, System.Nullable<double> timeout=null);
Parameters#
state System.Nullable<LoadState>
The load state to wait for.
timeout System.Nullable<System.Double>
Maximum time in milliseconds to wait.
Returns#
WaitForRequestAsync(string, Nullable<double>) Method#
Waits for a network request matching the URL pattern.
System.Threading.Tasks.Task<Motus.Abstractions.IRequest> WaitForRequestAsync(string urlPattern, System.Nullable<double> timeout=null);
Parameters#
urlPattern System.String
The URL pattern to match.
timeout System.Nullable<System.Double>
Maximum time in milliseconds to wait.
Returns#
System.Threading.Tasks.Task<IRequest>
The matching request.
WaitForResponseAsync(string, Nullable<double>) Method#
Waits for a network response matching the URL pattern.
System.Threading.Tasks.Task<Motus.Abstractions.IResponse> WaitForResponseAsync(string urlPattern, System.Nullable<double> timeout=null);
Parameters#
urlPattern System.String
The URL pattern to match.
timeout System.Nullable<System.Double>
Maximum time in milliseconds to wait.
Returns#
System.Threading.Tasks.Task<IResponse>
The matching response.
WaitForTimeoutAsync(double) Method#
Waits for a specified amount of time.
System.Threading.Tasks.Task WaitForTimeoutAsync(double timeout);
Parameters#
timeout System.Double
The time to wait in milliseconds.
Returns#
WaitForURLAsync(string, NavigationOptions) Method#
Waits for a matching URL navigation.
System.Threading.Tasks.Task WaitForURLAsync(string urlPattern, Motus.Abstractions.NavigationOptions? options=null);
Parameters#
urlPattern System.String
The URL pattern to match.
options NavigationOptions
Navigation options.
Returns#
Events#
Close Event#
Raised when the page closes.
event EventHandler? Close;
Event Type#
Console Event#
Raised when a console message is logged.
event EventHandler<ConsoleMessageEventArgs>? Console;
Event Type#
System.EventHandler<ConsoleMessageEventArgs>
Dialog Event#
Raised when a JavaScript dialog is opened.
event EventHandler<DialogEventArgs>? Dialog;
Event Type#
System.EventHandler<DialogEventArgs>
Download Event#
Raised when a download is started.
event EventHandler<IDownload>? Download;
Event Type#
System.EventHandler<IDownload>
FileChooser Event#
Raised when a file chooser is opened.
event EventHandler<IFileChooser>? FileChooser;
Event Type#
System.EventHandler<IFileChooser>
FrameAttached Event#
Raised when a frame is added to the page.
event EventHandler<IFrame>? FrameAttached;
Event Type#
Remarks#
Raised for every frame, including one that renders in its own process, which is announced as it is discovered rather than as part of the embedding page's frame tree.
FrameDetached Event#
Raised when a frame is removed from the page.
event EventHandler<IFrame>? FrameDetached;
Event Type#
FrameNavigated Event#
Raised when a frame in the page navigates.
event EventHandler<IFrame>? FrameNavigated;
Event Type#
PageError Event#
Raised when an uncaught exception occurs in the page.
event EventHandler<PageErrorEventArgs>? PageError;
Event Type#
System.EventHandler<PageErrorEventArgs>
Popup Event#
Raised when this page opens another one, through window.open or a link with
target="_blank". The new page is also in Pages.
event EventHandler<IPage>? Popup;
Event Type#
Remarks#
The page handed over is ready to be driven: its domains are enabled and its frame tree is
read, so a handler can navigate it, wait on it, or close it without any further step. It
may still be on about:blank at that moment, since the browser opens the tab before
the document it was asked for arrives, so wait on the page rather than reading its URL
straight away.
Request Event#
Raised when a network request is made.
event EventHandler<RequestEventArgs>? Request;
Event Type#
System.EventHandler<RequestEventArgs>
RequestFailed Event#
Raised when a network request fails.
event EventHandler<RequestEventArgs>? RequestFailed;
Event Type#
System.EventHandler<RequestEventArgs>
RequestFinished Event#
Raised when a network request finishes.
event EventHandler<RequestEventArgs>? RequestFinished;
Event Type#
System.EventHandler<RequestEventArgs>
Response Event#
Raised when a network response is received.
event EventHandler<ResponseEventArgs>? Response;