Table of Contents

Interface IFrame

Namespace
Microsoft.Playwright
Assembly
Microsoft.Playwright.dll

At every point of time, page exposes its current frame tree via the MainFrame and ChildFrames methods.

IFrame object's lifecycle is controlled by three events, dispatched on the page object:

  • FrameAttached - fired when the frame gets attached to the page. A Frame can be attached to the page only once.
  • FrameNavigated - fired when the frame commits navigation to a different URL.
  • FrameDetached - fired when the frame gets detached from the page. A Frame can be detached from the page only once.

An example of dumping frame tree:

using Microsoft.Playwright;
using System;
using System.Threading.Tasks;

class FrameExamples { public static async Task Main() { using var playwright = await Playwright.CreateAsync(); await using var browser = await playwright.Firefox.LaunchAsync(); var page = await browser.NewPageAsync();

    await page.GotoAsync("https://www.bing.com");
    DumpFrameTree(page.MainFrame, string.Empty);
}

private static void DumpFrameTree(IFrame frame, string indent)
{
    Console.WriteLine($"{indent}{frame.Url}");
    foreach (var child in frame.ChildFrames)
        DumpFrameTree(child, indent + " ");
}

}

public interface IFrame

Properties

ChildFrames

IReadOnlyList<IFrame> ChildFrames { get; }

Property Value

IReadOnlyList<IFrame>

IsDetached

Returns true if the frame has been detached, or false otherwise.

bool IsDetached { get; }

Property Value

bool

Name

Returns frame's name attribute as specified in the tag.

If the name is empty, returns the id attribute instead.

string Name { get; }

Property Value

string

Remarks

This value is calculated once when the frame is created, and will not update if the attribute is changed later.

Page

Returns the page containing this frame.

IPage Page { get; }

Property Value

IPage

ParentFrame

Parent frame, if any. Detached frames and main frames return null.

IFrame? ParentFrame { get; }

Property Value

IFrame

Url

Returns frame's url.

string Url { get; }

Property Value

string

Methods

AddScriptTagAsync(FrameAddScriptTagOptions?)

Returns the added tag when the script's onload fires or when the script content was injected into frame.

Adds a <script> tag into the page with the desired url or content.

Task<IElementHandle> AddScriptTagAsync(FrameAddScriptTagOptions? options = null)

Parameters

options FrameAddScriptTagOptions

Call options

Returns

Task<IElementHandle>

AddStyleTagAsync(FrameAddStyleTagOptions?)

Returns the added tag when the stylesheet's onload fires or when the CSS content was injected into frame.

Adds a <link rel="stylesheet"> tag into the page with the desired url or a <style type="text/css"> tag with the content.

Task<IElementHandle> AddStyleTagAsync(FrameAddStyleTagOptions? options = null)

Parameters

options FrameAddStyleTagOptions

Call options

Returns

Task<IElementHandle>

CheckAsync(string, FrameCheckOptions?)

Use locator-based CheckAsync(LocatorCheckOptions?) instead. Read more about locators.

This method checks an element matching selector by performing the following steps:

When all steps combined have not finished during the specified timeout, this method throws a TimeoutException. Passing zero timeout disables this.

Task CheckAsync(string selector, FrameCheckOptions? options = null)

Parameters

selector string

A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.

options FrameCheckOptions

Call options

Returns

Task

ClickAsync(string, FrameClickOptions?)

Use locator-based ClickAsync(LocatorClickOptions?) instead. Read more about locators.

This method clicks an element matching selector by performing the following steps:

When all steps combined have not finished during the specified timeout, this method throws a TimeoutException. Passing zero timeout disables this.

Task ClickAsync(string selector, FrameClickOptions? options = null)

Parameters

selector string

A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.

options FrameClickOptions

Call options

Returns

Task

ContentAsync()

Gets the full HTML contents of the frame, including the doctype.

Task<string> ContentAsync()

Returns

Task<string>

DblClickAsync(string, FrameDblClickOptions?)

Use locator-based DblClickAsync(LocatorDblClickOptions?) instead. Read more about locators.

This method double clicks an element matching selector by performing the following steps:

When all steps combined have not finished during the specified timeout, this method throws a TimeoutException. Passing zero timeout disables this.

Task DblClickAsync(string selector, FrameDblClickOptions? options = null)

Parameters

selector string

A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.

options FrameDblClickOptions

Call options

Returns

Task

Remarks

frame.dblclick() dispatches two click events and a single dblclick event.

DispatchEventAsync(string, string, object?, FrameDispatchEventOptions?)

Use locator-based DispatchEventAsync(string, object?, LocatorDispatchEventOptions?) instead. Read more about locators.

The snippet below dispatches the click event on the element. Regardless of the visibility state of the element, click is dispatched. This is equivalent to calling element.click().

**Usage**

await frame.DispatchEventAsync("button#submit", "click");

Under the hood, it creates an instance of an event based on the given type, initializes it with eventInit properties and dispatches it on the element. Events are composed, cancelable and bubble by default.

Since eventInit is event-specific, please refer to the events documentation for the lists of initial properties:

You can also specify JSHandle as the property value if you want live objects to be passed into the event:

// Note you can only create DataTransfer in Chromium and Firefox
var dataTransfer = await frame.EvaluateHandleAsync("() => new DataTransfer()");
await frame.DispatchEventAsync("#source", "dragstart", new { dataTransfer });
Task DispatchEventAsync(string selector, string type, object? eventInit = null, FrameDispatchEventOptions? options = null)

Parameters

selector string

A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.

type string

DOM event type: "click", "dragstart", etc.

eventInit object

Optional event-specific initialization properties.

options FrameDispatchEventOptions

Call options

Returns

Task

DragAndDropAsync(string, string, FrameDragAndDropOptions?)

Task DragAndDropAsync(string source, string target, FrameDragAndDropOptions? options = null)

Parameters

source string

A selector to search for an element to drag. If there are multiple elements satisfying the selector, the first will be used.

target string

A selector to search for an element to drop onto. If there are multiple elements satisfying the selector, the first will be used.

options FrameDragAndDropOptions

Call options

Returns

Task

EvalOnSelectorAllAsync(string, string, object)

Task<JsonElement?> EvalOnSelectorAllAsync(string selector, string expression, object arg = null)

Parameters

selector string
expression string
arg object

Returns

Task<JsonElement?>

EvalOnSelectorAllAsync<T>(string, string, object?)

In most cases, EvaluateAllAsync<T>(string, object?), other ILocator helper methods and web-first assertions do a better job.

Returns the return value of expression.

The method finds all elements matching the specified selector within the frame and passes an array of matched elements as a first argument to expression.

If expression returns a Task, then EvalOnSelectorAllAsync(string, string, object) would wait for the promise to resolve and return its value.

**Usage**

var divsCount = await frame.EvalOnSelectorAllAsync<bool>("div", "(divs, min) => divs.length >= min", 10);
Task<T> EvalOnSelectorAllAsync<T>(string selector, string expression, object? arg = null)

Parameters

selector string

A selector to query for.

expression string

JavaScript expression to be evaluated in the browser context. If the expression evaluates to a function, the function is automatically invoked.

arg object

Optional argument to pass to expression.

Returns

Task<T>

Type Parameters

T

EvalOnSelectorAsync(string, string, object)

Task<JsonElement?> EvalOnSelectorAsync(string selector, string expression, object arg = null)

Parameters

selector string
expression string
arg object

Returns

Task<JsonElement?>

EvalOnSelectorAsync<T>(string, string, object?, FrameEvalOnSelectorOptions?)

This method does not wait for the element to pass the actionability checks and therefore can lead to the flaky tests. Use EvaluateAsync(string, object, LocatorEvaluateOptions), other ILocator helper methods or web-first assertions instead.

Returns the return value of expression.

The method finds an element matching the specified selector within the frame and passes it as a first argument to expression. If no elements match the selector, the method throws an error.

If expression returns a Task, then EvalOnSelectorAsync(string, string, object) would wait for the promise to resolve and return its value.

**Usage**

var searchValue = await frame.EvalOnSelectorAsync<string>("#search", "el => el.value");
var preloadHref = await frame.EvalOnSelectorAsync<string>("link[rel=preload]", "el => el.href");
var html = await frame.EvalOnSelectorAsync(".main-container", "(e, suffix) => e.outerHTML + suffix", "hello");
Task<T> EvalOnSelectorAsync<T>(string selector, string expression, object? arg = null, FrameEvalOnSelectorOptions? options = null)

Parameters

selector string

A selector to query for.

expression string

JavaScript expression to be evaluated in the browser context. If the expression evaluates to a function, the function is automatically invoked.

arg object

Optional argument to pass to expression.

options FrameEvalOnSelectorOptions

Call options

Returns

Task<T>

Type Parameters

T

EvaluateAsync(string, object)

Task<JsonElement?> EvaluateAsync(string expression, object arg = null)

Parameters

expression string
arg object

Returns

Task<JsonElement?>

EvaluateAsync<T>(string, object?)

Returns the return value of expression.

If the function passed to the EvaluateAsync(string, object) returns a Task, then EvaluateAsync(string, object) would wait for the promise to resolve and return its value.

If the function passed to the EvaluateAsync(string, object) returns a non- value, then EvaluateAsync(string, object) returns undefined. Playwright also supports transferring some additional values that are not serializable by JSON: -0, NaN, Infinity, -Infinity.

**Usage**

var result = await frame.EvaluateAsync<int>("([x, y]) => Promise.resolve(x * y)", new[] { 7, 8 });
Console.WriteLine(result);

A string can also be passed in instead of a function.

Console.WriteLine(await frame.EvaluateAsync<int>("1 + 2")); // prints "3"

IElementHandle instances can be passed as an argument to the EvaluateAsync(string, object):

var bodyHandle = await frame.EvaluateAsync("document.body");
var html = await frame.EvaluateAsync<string>("([body, suffix]) => body.innerHTML + suffix", new object [] { bodyHandle, "hello" });
await bodyHandle.DisposeAsync();
Task<T> EvaluateAsync<T>(string expression, object? arg = null)

Parameters

expression string

JavaScript expression to be evaluated in the browser context. If the expression evaluates to a function, the function is automatically invoked.

arg object

Optional argument to pass to expression.

Returns

Task<T>

Type Parameters

T

EvaluateHandleAsync(string, object?)

Returns the return value of expression as a IJSHandle.

The only difference between EvaluateAsync(string, object) and EvaluateHandleAsync(string, object?) is that EvaluateHandleAsync(string, object?) returns IJSHandle.

If the function, passed to the EvaluateHandleAsync(string, object?), returns a Task, then EvaluateHandleAsync(string, object?) would wait for the promise to resolve and return its value.

**Usage**

// Handle for the window object.
var aWindowHandle = await frame.EvaluateHandleAsync("() => Promise.resolve(window)");

A string can also be passed in instead of a function.

var docHandle = await frame.EvaluateHandleAsync("document"); // Handle for the `document`

IJSHandle instances can be passed as an argument to the EvaluateHandleAsync(string, object?):

var handle = await frame.EvaluateHandleAsync("() => document.body");
var resultHandle = await frame.EvaluateHandleAsync("([body, suffix]) => body.innerHTML + suffix", new object[] { handle, "hello" });
Console.WriteLine(await resultHandle.JsonValueAsync<string>());
await resultHandle.DisposeAsync();
Task<IJSHandle> EvaluateHandleAsync(string expression, object? arg = null)

Parameters

expression string

JavaScript expression to be evaluated in the browser context. If the expression evaluates to a function, the function is automatically invoked.

arg object

Optional argument to pass to expression.

Returns

Task<IJSHandle>

FillAsync(string, string, FrameFillOptions?)

Use locator-based FillAsync(string, LocatorFillOptions?) instead. Read more about locators.

This method waits for an element matching selector, waits for actionability checks, focuses the element, fills it and triggers an input event after filling. Note that you can pass an empty string to clear the input field.

If the target element is not an <input>, <textarea> or [contenteditable] element, this method throws an error. However, if the element is inside the <label> element that has an associated control, the control will be filled instead.

To send fine-grained keyboard events, use PressSequentiallyAsync(string, LocatorPressSequentiallyOptions?).

Task FillAsync(string selector, string value, FrameFillOptions? options = null)

Parameters

selector string

A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.

value string

Value to fill for the <input>, <textarea> or [contenteditable] element.

options FrameFillOptions

Call options

Returns

Task

FocusAsync(string, FrameFocusOptions?)

Use locator-based FocusAsync(LocatorFocusOptions?) instead. Read more about locators.

This method fetches an element with selector and focuses it. If there's no element matching selector, the method waits until a matching element appears in the DOM.

Task FocusAsync(string selector, FrameFocusOptions? options = null)

Parameters

selector string

A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.

options FrameFocusOptions

Call options

Returns

Task

FrameElementAsync()

Returns the frame or iframe element handle which corresponds to this frame.

This is an inverse of ContentFrameAsync(). Note that returned handle actually belongs to the parent frame.

This method throws an error if the frame has been detached before frameElement() returns.

**Usage**

var frameElement = await frame.FrameElementAsync();
var contentFrame = await frameElement.ContentFrameAsync();
Console.WriteLine(frame == contentFrame); // -> True
Task<IElementHandle> FrameElementAsync()

Returns

Task<IElementHandle>

FrameLocator(string)

When working with iframes, you can create a frame locator that will enter the iframe and allow selecting elements in that iframe.

**Usage**

Following snippet locates element with text "Submit" in the iframe with id my-frame, like <iframe id="my-frame">:

var locator = frame.FrameLocator("#my-iframe").GetByText("Submit");
await locator.ClickAsync();
IFrameLocator FrameLocator(string selector)

Parameters

selector string

A selector to use when resolving DOM element.

Returns

IFrameLocator

GetAttributeAsync(string, string, FrameGetAttributeOptions?)

Use locator-based GetAttributeAsync(string, LocatorGetAttributeOptions?) instead. Read more about locators.

Returns element attribute value.

Task<string?> GetAttributeAsync(string selector, string name, FrameGetAttributeOptions? options = null)

Parameters

selector string

A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.

name string

Attribute name to get the value for.

options FrameGetAttributeOptions

Call options

Returns

Task<string>

GetByAltText(string, FrameGetByAltTextOptions?)

Allows locating elements by their alt text.

**Usage**

For example, this method will find the image by alt text "Playwright logo":

await page.GetByAltText("Playwright logo").ClickAsync();
ILocator GetByAltText(string text, FrameGetByAltTextOptions? options = null)

Parameters

text string

Text to locate the element for.

options FrameGetByAltTextOptions

Call options

Returns

ILocator

GetByAltText(Regex, FrameGetByAltTextOptions?)

Allows locating elements by their alt text.

**Usage**

For example, this method will find the image by alt text "Playwright logo":

await page.GetByAltText("Playwright logo").ClickAsync();
ILocator GetByAltText(Regex text, FrameGetByAltTextOptions? options = null)

Parameters

text Regex

Text to locate the element for.

options FrameGetByAltTextOptions

Call options

Returns

ILocator

GetByLabel(string, FrameGetByLabelOptions?)

Allows locating input elements by the text of the associated <label> or aria-labelledby element, or by the aria-label attribute.

**Usage**

For example, this method will find inputs by label "Username" and "Password" in the following DOM:

await page.GetByLabel("Username").FillAsync("john");
await page.GetByLabel("Password").FillAsync("secret");
ILocator GetByLabel(string text, FrameGetByLabelOptions? options = null)

Parameters

text string

Text to locate the element for.

options FrameGetByLabelOptions

Call options

Returns

ILocator

GetByLabel(Regex, FrameGetByLabelOptions?)

Allows locating input elements by the text of the associated <label> or aria-labelledby element, or by the aria-label attribute.

**Usage**

For example, this method will find inputs by label "Username" and "Password" in the following DOM:

await page.GetByLabel("Username").FillAsync("john");
await page.GetByLabel("Password").FillAsync("secret");
ILocator GetByLabel(Regex text, FrameGetByLabelOptions? options = null)

Parameters

text Regex

Text to locate the element for.

options FrameGetByLabelOptions

Call options

Returns

ILocator

GetByPlaceholder(string, FrameGetByPlaceholderOptions?)

Allows locating input elements by the placeholder text.

**Usage**

For example, consider the following DOM structure.

You can fill the input after locating it by the placeholder text:

await page
    .GetByPlaceholder("name@example.com")
    .FillAsync("playwright@microsoft.com");
ILocator GetByPlaceholder(string text, FrameGetByPlaceholderOptions? options = null)

Parameters

text string

Text to locate the element for.

options FrameGetByPlaceholderOptions

Call options

Returns

ILocator

GetByPlaceholder(Regex, FrameGetByPlaceholderOptions?)

Allows locating input elements by the placeholder text.

**Usage**

For example, consider the following DOM structure.

You can fill the input after locating it by the placeholder text:

await page
    .GetByPlaceholder("name@example.com")
    .FillAsync("playwright@microsoft.com");
ILocator GetByPlaceholder(Regex text, FrameGetByPlaceholderOptions? options = null)

Parameters

text Regex

Text to locate the element for.

options FrameGetByPlaceholderOptions

Call options

Returns

ILocator

GetByRole(AriaRole, FrameGetByRoleOptions?)

Allows locating elements by their ARIA role, ARIA attributes and accessible name.

**Usage**

Consider the following DOM structure.

You can locate each element by it's implicit role:

await Expect(Page
    .GetByRole(AriaRole.Heading, new() { Name = "Sign up" }))
    .ToBeVisibleAsync();

await page .GetByRole(AriaRole.Checkbox, new() { Name = "Subscribe" }) .CheckAsync();

await page .GetByRole(AriaRole.Button, new() { NameRegex = new Regex("submit", RegexOptions.IgnoreCase) }) .ClickAsync();

**Details**

Role selector **does not replace** accessibility audits and conformance tests, but rather gives early feedback about the ARIA guidelines.

Many html elements have an implicitly defined role that is recognized by the role selector. You can find all the supported roles here. ARIA guidelines **do not recommend** duplicating implicit roles and attributes by setting role and/or aria-* attributes to default values.

ILocator GetByRole(AriaRole role, FrameGetByRoleOptions? options = null)

Parameters

role AriaRole

Required aria role.

options FrameGetByRoleOptions

Call options

Returns

ILocator

GetByTestId(string)

Locate element by the test id.

**Usage**

Consider the following DOM structure.

You can locate the element by it's test id:

await page.GetByTestId("directions").ClickAsync();

**Details**

By default, the data-testid attribute is used as a test id. Use SetTestIdAttribute(string) to configure a different test id attribute if necessary.

ILocator GetByTestId(string testId)

Parameters

testId string

Id to locate the element by.

Returns

ILocator

GetByTestId(Regex)

Locate element by the test id.

**Usage**

Consider the following DOM structure.

You can locate the element by it's test id:

await page.GetByTestId("directions").ClickAsync();

**Details**

By default, the data-testid attribute is used as a test id. Use SetTestIdAttribute(string) to configure a different test id attribute if necessary.

ILocator GetByTestId(Regex testId)

Parameters

testId Regex

Id to locate the element by.

Returns

ILocator

GetByText(string, FrameGetByTextOptions?)

Allows locating elements that contain given text.

See also Filter(LocatorFilterOptions?) that allows to match by another criteria, like an accessible role, and then filter by the text content.

**Usage**

Consider the following DOM structure:

You can locate by text substring, exact string, or a regular expression:

// Matches <span>
page.GetByText("world");

// Matches first <div> page.GetByText("Hello world");

// Matches second <div> page.GetByText("Hello", new() { Exact = true });

// Matches both <div>s page.GetByText(new Regex("Hello"));

// Matches second <div> page.GetByText(new Regex("^hello$", RegexOptions.IgnoreCase));

**Details**

Matching by text always normalizes whitespace, even with exact match. For example, it turns multiple spaces into one, turns line breaks into spaces and ignores leading and trailing whitespace.

Input elements of the type button and submit are matched by their value instead of the text content. For example, locating by text "Log in" matches <input type=button value="Log in">.

ILocator GetByText(string text, FrameGetByTextOptions? options = null)

Parameters

text string

Text to locate the element for.

options FrameGetByTextOptions

Call options

Returns

ILocator

GetByText(Regex, FrameGetByTextOptions?)

Allows locating elements that contain given text.

See also Filter(LocatorFilterOptions?) that allows to match by another criteria, like an accessible role, and then filter by the text content.

**Usage**

Consider the following DOM structure:

You can locate by text substring, exact string, or a regular expression:

// Matches <span>
page.GetByText("world");

// Matches first <div> page.GetByText("Hello world");

// Matches second <div> page.GetByText("Hello", new() { Exact = true });

// Matches both <div>s page.GetByText(new Regex("Hello"));

// Matches second <div> page.GetByText(new Regex("^hello$", RegexOptions.IgnoreCase));

**Details**

Matching by text always normalizes whitespace, even with exact match. For example, it turns multiple spaces into one, turns line breaks into spaces and ignores leading and trailing whitespace.

Input elements of the type button and submit are matched by their value instead of the text content. For example, locating by text "Log in" matches <input type=button value="Log in">.

ILocator GetByText(Regex text, FrameGetByTextOptions? options = null)

Parameters

text Regex

Text to locate the element for.

options FrameGetByTextOptions

Call options

Returns

ILocator

GetByTitle(string, FrameGetByTitleOptions?)

Allows locating elements by their title attribute.

**Usage**

Consider the following DOM structure.

You can check the issues count after locating it by the title text:

await Expect(Page.GetByTitle("Issues count")).toHaveText("25 issues");
ILocator GetByTitle(string text, FrameGetByTitleOptions? options = null)

Parameters

text string

Text to locate the element for.

options FrameGetByTitleOptions

Call options

Returns

ILocator

GetByTitle(Regex, FrameGetByTitleOptions?)

Allows locating elements by their title attribute.

**Usage**

Consider the following DOM structure.

You can check the issues count after locating it by the title text:

await Expect(Page.GetByTitle("Issues count")).toHaveText("25 issues");
ILocator GetByTitle(Regex text, FrameGetByTitleOptions? options = null)

Parameters

text Regex

Text to locate the element for.

options FrameGetByTitleOptions

Call options

Returns

ILocator

GotoAsync(string, FrameGotoOptions?)

Returns the main resource response. In case of multiple redirects, the navigation will resolve with the response of the last redirect.

The method will throw an error if:

  • there's an SSL error (e.g. in case of self-signed certificates).
  • target URL is invalid.
  • the timeout is exceeded during navigation.
  • the remote server does not respond or is unreachable.
  • the main resource failed to load.

The method will not throw an error when any valid HTTP status code is returned by the remote server, including 404 "Not Found" and 500 "Internal Server Error". The status code for such responses can be retrieved by calling Status.

Task<IResponse?> GotoAsync(string url, FrameGotoOptions? options = null)

Parameters

url string

URL to navigate frame to. The url should include scheme, e.g. https://.

options FrameGotoOptions

Call options

Returns

Task<IResponse>

Remarks

The method either throws an error or returns a main resource response. The only exceptions are navigation to about:blank or navigation to the same URL with a different hash, which would succeed and return null.

Headless mode doesn't support navigation to a PDF document. See the upstream issue.

HoverAsync(string, FrameHoverOptions?)

Use locator-based HoverAsync(LocatorHoverOptions?) instead. Read more about locators.

This method hovers over an element matching selector by performing the following steps:

When all steps combined have not finished during the specified timeout, this method throws a TimeoutException. Passing zero timeout disables this.

Task HoverAsync(string selector, FrameHoverOptions? options = null)

Parameters

selector string

A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.

options FrameHoverOptions

Call options

Returns

Task

InnerHTMLAsync(string, FrameInnerHTMLOptions?)

Use locator-based InnerHTMLAsync(LocatorInnerHTMLOptions?) instead. Read more about locators.

Returns element.innerHTML.

Task<string> InnerHTMLAsync(string selector, FrameInnerHTMLOptions? options = null)

Parameters

selector string

A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.

options FrameInnerHTMLOptions

Call options

Returns

Task<string>

InnerTextAsync(string, FrameInnerTextOptions?)

Use locator-based InnerTextAsync(LocatorInnerTextOptions?) instead. Read more about locators.

Returns element.innerText.

Task<string> InnerTextAsync(string selector, FrameInnerTextOptions? options = null)

Parameters

selector string

A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.

options FrameInnerTextOptions

Call options

Returns

Task<string>

InputValueAsync(string, FrameInputValueOptions?)

Use locator-based InputValueAsync(LocatorInputValueOptions?) instead. Read more about locators.

Returns input.value for the selected <input> or <textarea> or <select> element.

Throws for non-input elements. However, if the element is inside the <label> element that has an associated control, returns the value of the control.

Task<string> InputValueAsync(string selector, FrameInputValueOptions? options = null)

Parameters

selector string

A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.

options FrameInputValueOptions

Call options

Returns

Task<string>

IsCheckedAsync(string, FrameIsCheckedOptions?)

Use locator-based IsCheckedAsync(LocatorIsCheckedOptions?) instead. Read more about locators.

Returns whether the element is checked. Throws if the element is not a checkbox or radio input.

Task<bool> IsCheckedAsync(string selector, FrameIsCheckedOptions? options = null)

Parameters

selector string

A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.

options FrameIsCheckedOptions

Call options

Returns

Task<bool>

IsDisabledAsync(string, FrameIsDisabledOptions?)

Use locator-based IsDisabledAsync(LocatorIsDisabledOptions?) instead. Read more about locators.

Returns whether the element is disabled, the opposite of enabled.

Task<bool> IsDisabledAsync(string selector, FrameIsDisabledOptions? options = null)

Parameters

selector string

A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.

options FrameIsDisabledOptions

Call options

Returns

Task<bool>

IsEditableAsync(string, FrameIsEditableOptions?)

Use locator-based IsEditableAsync(LocatorIsEditableOptions?) instead. Read more about locators.

Returns whether the element is editable.

Task<bool> IsEditableAsync(string selector, FrameIsEditableOptions? options = null)

Parameters

selector string

A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.

options FrameIsEditableOptions

Call options

Returns

Task<bool>

IsEnabledAsync(string, FrameIsEnabledOptions?)

Returns whether the element is enabled.

Task<bool> IsEnabledAsync(string selector, FrameIsEnabledOptions? options = null)

Parameters

selector string

A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.

options FrameIsEnabledOptions

Call options

Returns

Task<bool>

IsHiddenAsync(string, FrameIsHiddenOptions?)

Use locator-based IsHiddenAsync(LocatorIsHiddenOptions?) instead. Read more about locators.

Returns whether the element is hidden, the opposite of visible. selector that does not match any elements is considered hidden.

Task<bool> IsHiddenAsync(string selector, FrameIsHiddenOptions? options = null)

Parameters

selector string

A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.

options FrameIsHiddenOptions

Call options

Returns

Task<bool>

IsVisibleAsync(string, FrameIsVisibleOptions?)

Use locator-based IsVisibleAsync(LocatorIsVisibleOptions?) instead. Read more about locators.

Returns whether the element is visible. selector that does not match any elements is considered not visible.

Task<bool> IsVisibleAsync(string selector, FrameIsVisibleOptions? options = null)

Parameters

selector string

A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.

options FrameIsVisibleOptions

Call options

Returns

Task<bool>

Locator(string, FrameLocatorOptions?)

The method returns an element locator that can be used to perform actions on this page / frame. Locator is resolved to the element immediately before performing an action, so a series of actions on the same locator can in fact be performed on different DOM elements. That would happen if the DOM structure between those actions has changed.

Learn more about locators.

Learn more about locators.

ILocator Locator(string selector, FrameLocatorOptions? options = null)

Parameters

selector string

A selector to use when resolving DOM element.

options FrameLocatorOptions

Call options

Returns

ILocator

PressAsync(string, string, FramePressOptions?)

Use locator-based PressAsync(string, LocatorPressOptions?) instead. Read more about locators.

key can specify the intended keyboardEvent.key value or a single character to generate the text for. A superset of the key values can be found here. Examples of the keys are:

F1 - F12, Digit0- Digit9, KeyA- KeyZ, Backquote, Minus, Equal, Backslash, Backspace, Tab, Delete, Escape, ArrowDown, End, Enter, Home, Insert, PageDown, PageUp, ArrowRight, ArrowUp, etc.

Following modification shortcuts are also supported: Shift, Control, Alt, Meta, ShiftLeft, ControlOrMeta. ControlOrMeta resolves to Control on Windows and Linux and to Meta on macOS.

Holding down Shift will type the text that corresponds to the key in the upper case.

If key is a single character, it is case-sensitive, so the values a and A will generate different respective texts.

Shortcuts such as key: "Control+o", key: "Control++ or key: "Control+Shift+T" are supported as well. When specified with the modifier, modifier is pressed and being held while the subsequent key is being pressed.

Task PressAsync(string selector, string key, FramePressOptions? options = null)

Parameters

selector string

A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.

key string

Name of the key to press or a character to generate, such as ArrowLeft or a.

options FramePressOptions

Call options

Returns

Task

QuerySelectorAllAsync(string)

Use locator-based Locator(string, FrameLocatorOptions?) instead. Read more about locators.

Returns the ElementHandles pointing to the frame elements.

The method finds all elements matching the specified selector within the frame. If no elements match the selector, returns empty array.

Task<IReadOnlyList<IElementHandle>> QuerySelectorAllAsync(string selector)

Parameters

selector string

A selector to query for.

Returns

Task<IReadOnlyList<IElementHandle>>

Remarks

The use of IElementHandle is discouraged, use ILocator objects instead.

QuerySelectorAsync(string, FrameQuerySelectorOptions?)

Use locator-based Locator(string, FrameLocatorOptions?) instead. Read more about locators.

Returns the ElementHandle pointing to the frame element.

The method finds an element matching the specified selector within the frame. If no elements match the selector, returns null.

Task<IElementHandle?> QuerySelectorAsync(string selector, FrameQuerySelectorOptions? options = null)

Parameters

selector string

A selector to query for.

options FrameQuerySelectorOptions

Call options

Returns

Task<IElementHandle>

Remarks

The use of IElementHandle is discouraged, use ILocator objects and web-first assertions instead.

RunAndWaitForNavigationAsync(Func<Task>, FrameRunAndWaitForNavigationOptions?)

**DEPRECATED** This method is inherently racy, please use WaitForURLAsync(string, FrameWaitForURLOptions?) instead.

Waits for the frame navigation and returns the main resource response. In case of multiple redirects, the navigation will resolve with the response of the last redirect. In case of navigation to a different anchor or navigation due to History API usage, the navigation will resolve with null.

**Usage**

This method waits for the frame to navigate to a new URL. It is useful for when you run code which will indirectly cause the frame to navigate. Consider this example:

await frame.RunAndWaitForNavigationAsync(async () =>
{
    // Clicking the link will indirectly cause a navigation.
    await frame.ClickAsync("a.delayed-navigation");
});

// Resolves after navigation has finished

[Obsolete]
Task<IResponse?> RunAndWaitForNavigationAsync(Func<Task> action, FrameRunAndWaitForNavigationOptions? options = null)

Parameters

action Func<Task>

Action that triggers the event.

options FrameRunAndWaitForNavigationOptions

Call options

Returns

Task<IResponse>

Remarks

Usage of the History API to change the URL is considered a navigation.

SelectOptionAsync(string, IElementHandle, FrameSelectOptionOptions?)

Use locator-based SelectOptionAsync(string, LocatorSelectOptionOptions?) instead. Read more about locators.

This method waits for an element matching selector, waits for actionability checks, waits until all specified options are present in the <select> element and selects these options.

If the target element is not a <select> element, this method throws an error. However, if the element is inside the <label> element that has an associated control, the control will be used instead.

Returns the array of option values that have been successfully selected.

Triggers a change and input event once all the provided options have been selected.

**Usage**

// Single selection matching the value or label
await frame.SelectOptionAsync("select#colors", new[] { "blue" });
// single selection matching both the value and the label
await frame.SelectOptionAsync("select#colors", new[] { new SelectOptionValue() { Label = "blue" } });
// multiple selection
await frame.SelectOptionAsync("select#colors", new[] { "red", "green", "blue" });
Task<IReadOnlyList<string>> SelectOptionAsync(string selector, IElementHandle values, FrameSelectOptionOptions? options = null)

Parameters

selector string

A selector to query for.

values IElementHandle

Options to select. If the <select> has the multiple attribute, all matching options are selected, otherwise only the first option matching one of the passed options is selected. String values are matching both values and labels. Option is considered matching if all specified properties match.

options FrameSelectOptionOptions

Call options

Returns

Task<IReadOnlyList<string>>

SelectOptionAsync(string, SelectOptionValue, FrameSelectOptionOptions?)

Use locator-based SelectOptionAsync(string, LocatorSelectOptionOptions?) instead. Read more about locators.

This method waits for an element matching selector, waits for actionability checks, waits until all specified options are present in the <select> element and selects these options.

If the target element is not a <select> element, this method throws an error. However, if the element is inside the <label> element that has an associated control, the control will be used instead.

Returns the array of option values that have been successfully selected.

Triggers a change and input event once all the provided options have been selected.

**Usage**

// Single selection matching the value or label
await frame.SelectOptionAsync("select#colors", new[] { "blue" });
// single selection matching both the value and the label
await frame.SelectOptionAsync("select#colors", new[] { new SelectOptionValue() { Label = "blue" } });
// multiple selection
await frame.SelectOptionAsync("select#colors", new[] { "red", "green", "blue" });
Task<IReadOnlyList<string>> SelectOptionAsync(string selector, SelectOptionValue values, FrameSelectOptionOptions? options = null)

Parameters

selector string

A selector to query for.

values SelectOptionValue

Options to select. If the <select> has the multiple attribute, all matching options are selected, otherwise only the first option matching one of the passed options is selected. String values are matching both values and labels. Option is considered matching if all specified properties match.

options FrameSelectOptionOptions

Call options

Returns

Task<IReadOnlyList<string>>

SelectOptionAsync(string, IEnumerable<IElementHandle>, FrameSelectOptionOptions?)

Use locator-based SelectOptionAsync(string, LocatorSelectOptionOptions?) instead. Read more about locators.

This method waits for an element matching selector, waits for actionability checks, waits until all specified options are present in the <select> element and selects these options.

If the target element is not a <select> element, this method throws an error. However, if the element is inside the <label> element that has an associated control, the control will be used instead.

Returns the array of option values that have been successfully selected.

Triggers a change and input event once all the provided options have been selected.

**Usage**

// Single selection matching the value or label
await frame.SelectOptionAsync("select#colors", new[] { "blue" });
// single selection matching both the value and the label
await frame.SelectOptionAsync("select#colors", new[] { new SelectOptionValue() { Label = "blue" } });
// multiple selection
await frame.SelectOptionAsync("select#colors", new[] { "red", "green", "blue" });
Task<IReadOnlyList<string>> SelectOptionAsync(string selector, IEnumerable<IElementHandle> values, FrameSelectOptionOptions? options = null)

Parameters

selector string

A selector to query for.

values IEnumerable<IElementHandle>

Options to select. If the <select> has the multiple attribute, all matching options are selected, otherwise only the first option matching one of the passed options is selected. String values are matching both values and labels. Option is considered matching if all specified properties match.

options FrameSelectOptionOptions

Call options

Returns

Task<IReadOnlyList<string>>

SelectOptionAsync(string, IEnumerable<SelectOptionValue>, FrameSelectOptionOptions?)

Use locator-based SelectOptionAsync(string, LocatorSelectOptionOptions?) instead. Read more about locators.

This method waits for an element matching selector, waits for actionability checks, waits until all specified options are present in the <select> element and selects these options.

If the target element is not a <select> element, this method throws an error. However, if the element is inside the <label> element that has an associated control, the control will be used instead.

Returns the array of option values that have been successfully selected.

Triggers a change and input event once all the provided options have been selected.

**Usage**

// Single selection matching the value or label
await frame.SelectOptionAsync("select#colors", new[] { "blue" });
// single selection matching both the value and the label
await frame.SelectOptionAsync("select#colors", new[] { new SelectOptionValue() { Label = "blue" } });
// multiple selection
await frame.SelectOptionAsync("select#colors", new[] { "red", "green", "blue" });
Task<IReadOnlyList<string>> SelectOptionAsync(string selector, IEnumerable<SelectOptionValue> values, FrameSelectOptionOptions? options = null)

Parameters

selector string

A selector to query for.

values IEnumerable<SelectOptionValue>

Options to select. If the <select> has the multiple attribute, all matching options are selected, otherwise only the first option matching one of the passed options is selected. String values are matching both values and labels. Option is considered matching if all specified properties match.

options FrameSelectOptionOptions

Call options

Returns

Task<IReadOnlyList<string>>

SelectOptionAsync(string, IEnumerable<string>, FrameSelectOptionOptions?)

Use locator-based SelectOptionAsync(string, LocatorSelectOptionOptions?) instead. Read more about locators.

This method waits for an element matching selector, waits for actionability checks, waits until all specified options are present in the <select> element and selects these options.

If the target element is not a <select> element, this method throws an error. However, if the element is inside the <label> element that has an associated control, the control will be used instead.

Returns the array of option values that have been successfully selected.

Triggers a change and input event once all the provided options have been selected.

**Usage**

// Single selection matching the value or label
await frame.SelectOptionAsync("select#colors", new[] { "blue" });
// single selection matching both the value and the label
await frame.SelectOptionAsync("select#colors", new[] { new SelectOptionValue() { Label = "blue" } });
// multiple selection
await frame.SelectOptionAsync("select#colors", new[] { "red", "green", "blue" });
Task<IReadOnlyList<string>> SelectOptionAsync(string selector, IEnumerable<string> values, FrameSelectOptionOptions? options = null)

Parameters

selector string

A selector to query for.

values IEnumerable<string>

Options to select. If the <select> has the multiple attribute, all matching options are selected, otherwise only the first option matching one of the passed options is selected. String values are matching both values and labels. Option is considered matching if all specified properties match.

options FrameSelectOptionOptions

Call options

Returns

Task<IReadOnlyList<string>>

SelectOptionAsync(string, string, FrameSelectOptionOptions?)

Use locator-based SelectOptionAsync(string, LocatorSelectOptionOptions?) instead. Read more about locators.

This method waits for an element matching selector, waits for actionability checks, waits until all specified options are present in the <select> element and selects these options.

If the target element is not a <select> element, this method throws an error. However, if the element is inside the <label> element that has an associated control, the control will be used instead.

Returns the array of option values that have been successfully selected.

Triggers a change and input event once all the provided options have been selected.

**Usage**

// Single selection matching the value or label
await frame.SelectOptionAsync("select#colors", new[] { "blue" });
// single selection matching both the value and the label
await frame.SelectOptionAsync("select#colors", new[] { new SelectOptionValue() { Label = "blue" } });
// multiple selection
await frame.SelectOptionAsync("select#colors", new[] { "red", "green", "blue" });
Task<IReadOnlyList<string>> SelectOptionAsync(string selector, string values, FrameSelectOptionOptions? options = null)

Parameters

selector string

A selector to query for.

values string

Options to select. If the <select> has the multiple attribute, all matching options are selected, otherwise only the first option matching one of the passed options is selected. String values are matching both values and labels. Option is considered matching if all specified properties match.

options FrameSelectOptionOptions

Call options

Returns

Task<IReadOnlyList<string>>

SetCheckedAsync(string, bool, FrameSetCheckedOptions?)

Use locator-based SetCheckedAsync(bool, LocatorSetCheckedOptions?) instead. Read more about locators.

This method checks or unchecks an element matching selector by performing the following steps:

When all steps combined have not finished during the specified timeout, this method throws a TimeoutException. Passing zero timeout disables this.

Task SetCheckedAsync(string selector, bool checkedState, FrameSetCheckedOptions? options = null)

Parameters

selector string

A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.

checkedState bool

Whether to check or uncheck the checkbox.

options FrameSetCheckedOptions

Call options

Returns

Task

SetContentAsync(string, FrameSetContentOptions?)

This method internally calls document.write(), inheriting all its specific characteristics and behaviors.

Task SetContentAsync(string html, FrameSetContentOptions? options = null)

Parameters

html string

HTML markup to assign to the page.

options FrameSetContentOptions

Call options

Returns

Task

SetInputFilesAsync(string, FilePayload, FrameSetInputFilesOptions?)

Use locator-based SetInputFilesAsync(string, LocatorSetInputFilesOptions?) instead. Read more about locators.

Sets the value of the file input to these file paths or files. If some of the filePaths are relative paths, then they are resolved relative to the current working directory. For empty array, clears the selected files.

This method expects selector to point to an input element. However, if the element is inside the <label> element that has an associated control, targets the control instead.

Task SetInputFilesAsync(string selector, FilePayload files, FrameSetInputFilesOptions? options = null)

Parameters

selector string

A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.

files FilePayload
options FrameSetInputFilesOptions

Call options

Returns

Task

SetInputFilesAsync(string, IEnumerable<FilePayload>, FrameSetInputFilesOptions?)

Use locator-based SetInputFilesAsync(string, LocatorSetInputFilesOptions?) instead. Read more about locators.

Sets the value of the file input to these file paths or files. If some of the filePaths are relative paths, then they are resolved relative to the current working directory. For empty array, clears the selected files.

This method expects selector to point to an input element. However, if the element is inside the <label> element that has an associated control, targets the control instead.

Task SetInputFilesAsync(string selector, IEnumerable<FilePayload> files, FrameSetInputFilesOptions? options = null)

Parameters

selector string

A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.

files IEnumerable<FilePayload>
options FrameSetInputFilesOptions

Call options

Returns

Task

SetInputFilesAsync(string, IEnumerable<string>, FrameSetInputFilesOptions?)

Use locator-based SetInputFilesAsync(string, LocatorSetInputFilesOptions?) instead. Read more about locators.

Sets the value of the file input to these file paths or files. If some of the filePaths are relative paths, then they are resolved relative to the current working directory. For empty array, clears the selected files.

This method expects selector to point to an input element. However, if the element is inside the <label> element that has an associated control, targets the control instead.

Task SetInputFilesAsync(string selector, IEnumerable<string> files, FrameSetInputFilesOptions? options = null)

Parameters

selector string

A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.

files IEnumerable<string>
options FrameSetInputFilesOptions

Call options

Returns

Task

SetInputFilesAsync(string, string, FrameSetInputFilesOptions?)

Use locator-based SetInputFilesAsync(string, LocatorSetInputFilesOptions?) instead. Read more about locators.

Sets the value of the file input to these file paths or files. If some of the filePaths are relative paths, then they are resolved relative to the current working directory. For empty array, clears the selected files.

This method expects selector to point to an input element. However, if the element is inside the <label> element that has an associated control, targets the control instead.

Task SetInputFilesAsync(string selector, string files, FrameSetInputFilesOptions? options = null)

Parameters

selector string

A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.

files string
options FrameSetInputFilesOptions

Call options

Returns

Task

TapAsync(string, FrameTapOptions?)

Use locator-based TapAsync(LocatorTapOptions?) instead. Read more about locators.

This method taps an element matching selector by performing the following steps:

When all steps combined have not finished during the specified timeout, this method throws a TimeoutException. Passing zero timeout disables this.

Task TapAsync(string selector, FrameTapOptions? options = null)

Parameters

selector string

A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.

options FrameTapOptions

Call options

Returns

Task

Remarks

frame.tap() requires that the hasTouch option of the browser context be set to true.

TextContentAsync(string, FrameTextContentOptions?)

Use locator-based TextContentAsync(LocatorTextContentOptions?) instead. Read more about locators.

Returns element.textContent.

Task<string?> TextContentAsync(string selector, FrameTextContentOptions? options = null)

Parameters

selector string

A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.

options FrameTextContentOptions

Call options

Returns

Task<string>

TitleAsync()

Returns the page title.

Task<string> TitleAsync()

Returns

Task<string>

TypeAsync(string, string, FrameTypeOptions?)

**DEPRECATED** In most cases, you should use FillAsync(string, LocatorFillOptions?) instead. You only need to press keys one by one if there is special keyboard handling on the page - in this case use PressSequentiallyAsync(string, LocatorPressSequentiallyOptions?).

Sends a keydown, keypress/input, and keyup event for each character in the text. frame.type can be used to send fine-grained keyboard events. To fill values in form fields, use FillAsync(string, string, FrameFillOptions?).

To press a special key, like Control or ArrowDown, use PressAsync(string, KeyboardPressOptions?).

**Usage**

[Obsolete]
Task TypeAsync(string selector, string text, FrameTypeOptions? options = null)

Parameters

selector string

A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.

text string

A text to type into a focused element.

options FrameTypeOptions

Call options

Returns

Task

UncheckAsync(string, FrameUncheckOptions?)

Use locator-based UncheckAsync(LocatorUncheckOptions?) instead. Read more about locators.

This method checks an element matching selector by performing the following steps:

When all steps combined have not finished during the specified timeout, this method throws a TimeoutException. Passing zero timeout disables this.

Task UncheckAsync(string selector, FrameUncheckOptions? options = null)

Parameters

selector string

A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.

options FrameUncheckOptions

Call options

Returns

Task

WaitForFunctionAsync(string, object?, FrameWaitForFunctionOptions?)

Returns when the expression returns a truthy value, returns that value.

**Usage**

The WaitForFunctionAsync(string, object?, FrameWaitForFunctionOptions?) can be used to observe viewport size change:

using Microsoft.Playwright;
using System.Threading.Tasks;

class FrameExamples { public static async Task Main() { using var playwright = await Playwright.CreateAsync(); await using var browser = await playwright.Firefox.LaunchAsync(); var page = await browser.NewPageAsync(); await page.SetViewportSizeAsync(50, 50); await page.MainFrame.WaitForFunctionAsync("window.innerWidth < 100"); } }

To pass an argument to the predicate of frame.waitForFunction function:

var selector = ".foo";
await page.MainFrame.WaitForFunctionAsync("selector => !!document.querySelector(selector)", selector);
Task<IJSHandle> WaitForFunctionAsync(string expression, object? arg = null, FrameWaitForFunctionOptions? options = null)

Parameters

expression string

JavaScript expression to be evaluated in the browser context. If the expression evaluates to a function, the function is automatically invoked.

arg object

Optional argument to pass to expression.

options FrameWaitForFunctionOptions

Call options

Returns

Task<IJSHandle>

WaitForLoadStateAsync(LoadState?, FrameWaitForLoadStateOptions?)

Waits for the required load state to be reached.

This returns when the frame reaches a required load state, load by default. The navigation must have been committed when this method is called. If current document has already reached the required state, resolves immediately.

**Usage**

await frame.ClickAsync("button");
await frame.WaitForLoadStateAsync(); // Defaults to LoadState.Load
Task WaitForLoadStateAsync(LoadState? state = null, FrameWaitForLoadStateOptions? options = null)

Parameters

state LoadState?

Optional load state to wait for, defaults to load. If the state has been already reached while loading current document, the method resolves immediately. Can be one of:

  • 'load' - wait for the load event to be fired.
  • 'domcontentloaded' - wait for the DOMContentLoaded event to be fired.
  • 'networkidle' - **DISCOURAGED** wait until there are no network connections for at least 500 ms. Don't use this method for testing, rely on web assertions to assess readiness instead.
options FrameWaitForLoadStateOptions

Call options

Returns

Task

Remarks

Most of the time, this method is not needed because Playwright auto-waits before every action.

WaitForNavigationAsync(FrameWaitForNavigationOptions?)

**DEPRECATED** This method is inherently racy, please use WaitForURLAsync(string, FrameWaitForURLOptions?) instead.

Waits for the frame navigation and returns the main resource response. In case of multiple redirects, the navigation will resolve with the response of the last redirect. In case of navigation to a different anchor or navigation due to History API usage, the navigation will resolve with null.

**Usage**

This method waits for the frame to navigate to a new URL. It is useful for when you run code which will indirectly cause the frame to navigate. Consider this example:

await frame.RunAndWaitForNavigationAsync(async () =>
{
    // Clicking the link will indirectly cause a navigation.
    await frame.ClickAsync("a.delayed-navigation");
});

// Resolves after navigation has finished

[Obsolete]
Task<IResponse?> WaitForNavigationAsync(FrameWaitForNavigationOptions? options = null)

Parameters

options FrameWaitForNavigationOptions

Call options

Returns

Task<IResponse>

Remarks

Usage of the History API to change the URL is considered a navigation.

WaitForSelectorAsync(string, FrameWaitForSelectorOptions?)

Use web assertions that assert visibility or a locator-based WaitForAsync(LocatorWaitForOptions?) instead. Read more about locators.

Returns when element specified by selector satisfies state option. Returns null if waiting for hidden or detached.

Wait for the selector to satisfy state option (either appear/disappear from dom, or become visible/hidden). If at the moment of calling the method selector already satisfies the condition, the method will return immediately. If the selector doesn't satisfy the condition for the timeout milliseconds, the function will throw.

**Usage**

This method works across navigations:

using Microsoft.Playwright;
using System;
using System.Threading.Tasks;

class FrameExamples { public static async Task Main() { using var playwright = await Playwright.CreateAsync(); await using var browser = await playwright.Chromium.LaunchAsync(); var page = await browser.NewPageAsync();

    foreach (var currentUrl in new[] { "https://www.google.com", "https://bbc.com" })
    {
        await page.GotoAsync(currentUrl);
        element = await page.MainFrame.WaitForSelectorAsync("img");
        Console.WriteLine($"Loaded image: {await element.GetAttributeAsync("src")}");
    }
}

}

Task<IElementHandle?> WaitForSelectorAsync(string selector, FrameWaitForSelectorOptions? options = null)

Parameters

selector string

A selector to query for.

options FrameWaitForSelectorOptions

Call options

Returns

Task<IElementHandle>

Remarks

Playwright automatically waits for element to be ready before performing an action. Using ILocator objects and web-first assertions make the code wait-for-selector-free.

WaitForTimeoutAsync(float)

Never wait for timeout in production. Tests that wait for time are inherently flaky. Use ILocator actions and web assertions that wait automatically.

Waits for the given timeout in milliseconds.

Note that frame.waitForTimeout() should only be used for debugging. Tests using the timer in production are going to be flaky. Use signals such as network events, selectors becoming visible and others instead.

Task WaitForTimeoutAsync(float timeout)

Parameters

timeout float

A timeout to wait for

Returns

Task

WaitForURLAsync(Func<string, bool>, FrameWaitForURLOptions?)

Waits for the frame to navigate to the given URL.

**Usage**

await frame.ClickAsync("a.delayed-navigation"); // clicking the link will indirectly cause a navigation
await frame.WaitForURLAsync("**/target.html");
Task WaitForURLAsync(Func<string, bool> url, FrameWaitForURLOptions? options = null)

Parameters

url Func<string, bool>

A glob pattern, regex pattern or predicate receiving to match while waiting for the navigation. Note that if the parameter is a string without wildcard characters, the method will wait for navigation to URL that is exactly equal to the string.

options FrameWaitForURLOptions

Call options

Returns

Task

WaitForURLAsync(string, FrameWaitForURLOptions?)

Waits for the frame to navigate to the given URL.

**Usage**

await frame.ClickAsync("a.delayed-navigation"); // clicking the link will indirectly cause a navigation
await frame.WaitForURLAsync("**/target.html");
Task WaitForURLAsync(string url, FrameWaitForURLOptions? options = null)

Parameters

url string

A glob pattern, regex pattern or predicate receiving to match while waiting for the navigation. Note that if the parameter is a string without wildcard characters, the method will wait for navigation to URL that is exactly equal to the string.

options FrameWaitForURLOptions

Call options

Returns

Task

WaitForURLAsync(Regex, FrameWaitForURLOptions?)

Waits for the frame to navigate to the given URL.

**Usage**

await frame.ClickAsync("a.delayed-navigation"); // clicking the link will indirectly cause a navigation
await frame.WaitForURLAsync("**/target.html");
Task WaitForURLAsync(Regex url, FrameWaitForURLOptions? options = null)

Parameters

url Regex

A glob pattern, regex pattern or predicate receiving to match while waiting for the navigation. Note that if the parameter is a string without wildcard characters, the method will wait for navigation to URL that is exactly equal to the string.

options FrameWaitForURLOptions

Call options

Returns

Task