A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://playwright.dev/python/docs/api/class-framelocator below:

FrameLocator | Playwright Python

FrameLocator

FrameLocator represents a view to the iframe on the page. It captures the logic sufficient to retrieve the iframe and locate elements in that iframe. FrameLocator can be created with either locator.content_frame, page.frame_locator() or locator.frame_locator() method.

locator = page.locator("my-frame").content_frame.get_by_text("Submit")
locator.click()
locator = page.locator("#my-frame").content_frame.get_by_text("Submit")
await locator.click()

Strictness

Frame locators are strict. This means that all operations on frame locators will throw if more than one element matches a given selector.


page.locator('.result-frame').content_frame.get_by_role('button').click()


page.locator('.result-frame').first.content_frame.get_by_role('button').click()

await page.locator('.result-frame').content_frame.get_by_role('button').click()


await page.locator('.result-frame').first.content_frame.get_by_role('button').click()

Converting Locator to FrameLocator

If you have a Locator object pointing to an iframe it can be converted to FrameLocator using locator.content_frame.

Converting FrameLocator to Locator

If you have a FrameLocator object it can be converted to Locator pointing to the same iframe using frame_locator.owner.

Methods frame_locatorAdded in: v1.17 frameLocator.frame_locator

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

Usage

frame_locator.frame_locator(selector)

Arguments

Returns

get_by_alt_textAdded in: v1.27 frameLocator.get_by_alt_text

Allows locating elements by their alt text.

Usage

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

<img alt='Playwright logo'>
page.get_by_alt_text("Playwright logo").click()
await page.get_by_alt_text("Playwright logo").click()

Arguments

Returns

get_by_labelAdded in: v1.27 frameLocator.get_by_label

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:

<input aria-label="Username">
<label for="password-input">Password:</label>
<input id="password-input">
page.get_by_label("Username").fill("john")
page.get_by_label("Password").fill("secret")
await page.get_by_label("Username").fill("john")
await page.get_by_label("Password").fill("secret")

Arguments

Returns

get_by_placeholderAdded in: v1.27 frameLocator.get_by_placeholder

Allows locating input elements by the placeholder text.

Usage

For example, consider the following DOM structure.

<input type="email" placeholder="name@example.com" />

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

page.get_by_placeholder("name@example.com").fill("playwright@microsoft.com")
await page.get_by_placeholder("name@example.com").fill("playwright@microsoft.com")

Arguments

Returns

get_by_roleAdded in: v1.27 frameLocator.get_by_role

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

Usage

Consider the following DOM structure.

<h3>Sign up</h3>
<label>
<input type="checkbox" /> Subscribe
</label>
<br/>
<button>Submit</button>

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

expect(page.get_by_role("heading", name="Sign up")).to_be_visible()

page.get_by_role("checkbox", name="Subscribe").check()

page.get_by_role("button", name=re.compile("submit", re.IGNORECASE)).click()
await expect(page.get_by_role("heading", name="Sign up")).to_be_visible()

await page.get_by_role("checkbox", name="Subscribe").check()

await page.get_by_role("button", name=re.compile("submit", re.IGNORECASE)).click()

Arguments

Returns

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.

get_by_test_idAdded in: v1.27 frameLocator.get_by_test_id

Locate element by the test id.

Usage

Consider the following DOM structure.

<button data-testid="directions">Itinéraire</button>

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

page.get_by_test_id("directions").click()
await page.get_by_test_id("directions").click()

Arguments

Returns

Details

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

get_by_textAdded in: v1.27 frameLocator.get_by_text

Allows locating elements that contain given text.

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

Usage

Consider the following DOM structure:

<div>Hello <span>world</span></div>
<div>Hello</div>

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


page.get_by_text("world")


page.get_by_text("Hello world")


page.get_by_text("Hello", exact=True)


page.get_by_text(re.compile("Hello"))


page.get_by_text(re.compile("^hello$", re.IGNORECASE))

page.get_by_text("world")


page.get_by_text("Hello world")


page.get_by_text("Hello", exact=True)


page.get_by_text(re.compile("Hello"))


page.get_by_text(re.compile("^hello$", re.IGNORECASE))

Arguments

Returns

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">.

get_by_titleAdded in: v1.27 frameLocator.get_by_title

Allows locating elements by their title attribute.

Usage

Consider the following DOM structure.

<span title='Issues count'>25 issues</span>

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

expect(page.get_by_title("Issues count")).to_have_text("25 issues")
await expect(page.get_by_title("Issues count")).to_have_text("25 issues")

Arguments

Returns

locatorAdded in: v1.17 frameLocator.locator

The method finds an element matching the specified selector in the locator's subtree. It also accepts filter options, similar to locator.filter() method.

Learn more about locators.

Usage

frame_locator.locator(selector_or_locator)
frame_locator.locator(selector_or_locator, **kwargs)

Arguments

Returns

Properties ownerAdded in: v1.43 frameLocator.owner

Returns a Locator object pointing to the same iframe as this frame locator.

Useful when you have a FrameLocator object obtained somewhere, and later on would like to interact with the iframe element.

For a reverse operation, use locator.content_frame.

Usage

frame_locator = page.locator("iframe[name=\"embedded\"]").content_frame

locator = frame_locator.owner
expect(locator).to_be_visible()
frame_locator = page.locator("iframe[name=\"embedded\"]").content_frame

locator = frame_locator.owner
await expect(locator).to_be_visible()

Returns

Deprecated firstAdded in: v1.17 frameLocator.first

Returns locator to the first matching frame.

Usage

Returns

lastAdded in: v1.17 frameLocator.last

Returns locator to the last matching frame.

Usage

Returns

nthAdded in: v1.17 frameLocator.nth

Returns locator to the n-th matching frame. It's zero based, nth(0) selects the first frame.

Usage

Arguments

Returns


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4