class Playwright::FrameLocator
“‘
frameLocator = locator.frame_locator(“:scope”)
“`python sync
If you have a `Locator` object pointing to an `iframe` it can be converted to `FrameLocator` using [`:scope`](developer.mozilla.org/en-US/docs/Web/CSS/:scope) CSS selector:
**Converting Locator to FrameLocator**
“`
page.frame_locator(’.result-frame’).first.get_by_role(‘button’).click()
# Works because we explicitly tell locator to pick the first frame:
page.frame_locator(‘.result-frame’).get_by_role(‘button’).click()
# Throws if there are several frames in DOM:
“‘python sync
Frame locators are strict. This means that all operations on frame locators will throw if more than one element matches a given selector.
Strictness
“`
locator.click()
locator = page.frame_locator(“my-frame”).get_by_text(“Submit”)
“`python sync
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 [`method: Page.frameLocator`] or [`method: Locator.frameLocator`] method.
def first
def first wrap_impl(@impl.first) end
def frame_locator(selector)
When working with iframes, you can create a frame locator that will enter the iframe and allow selecting elements
def frame_locator(selector) wrap_impl(@impl.frame_locator(unwrap_impl(selector))) end
def get_by_alt_text(text, exact: nil)
page.get_by_alt_text("Playwright logo").click()
```python sync
```
```html
For example, this method will find the image by alt text "Playwright logo":
**Usage**
Allows locating elements by their alt text.
def get_by_alt_text(text, exact: nil) wrap_impl(@impl.get_by_alt_text(unwrap_impl(text), exact: unwrap_impl(exact))) end
def get_by_label(text, exact: nil)
page.get_by_label("Password").fill("secret")
page.get_by_label("Username").fill("john")
```python sync
```
```html
For example, this method will find inputs by label "Username" and "Password" in the following DOM:
**Usage**
Allows locating input elements by the text of the associated `
def get_by_label(text, exact: nil) wrap_impl(@impl.get_by_label(unwrap_impl(text), exact: unwrap_impl(exact))) end
def get_by_placeholder(text, exact: nil)
page.get_by_placeholder("name@example.com").fill("playwright@microsoft.com")
```python sync
You can fill the input after locating it by the placeholder text:
```
```html
For example, consider the following DOM structure.
**Usage**
Allows locating input elements by the placeholder text.
def get_by_placeholder(text, exact: nil) wrap_impl(@impl.get_by_placeholder(unwrap_impl(text), exact: unwrap_impl(exact))) end
def get_by_role(
Role selector **does not replace** accessibility audits and conformance tests, but rather gives early feedback about the ARIA guidelines.
**Details**
```
page.get_by_role("button", name=re.compile("submit", re.IGNORECASE)).click()
page.get_by_role("checkbox", name="Subscribe").check()
expect(page.get_by_role("heading", name="Sign up")).to_be_visible()
```python sync
You can locate each element by it's implicit role:
```
Subscribe
def get_by_role( role, checked: nil, disabled: nil, exact: nil, expanded: nil, includeHidden: nil, level: nil, name: nil, pressed: nil, selected: nil) wrap_impl(@impl.get_by_role(unwrap_impl(role), checked: unwrap_impl(checked), disabled: unwrap_impl(disabled), exact: unwrap_impl(exact), expanded: unwrap_impl(expanded), includeHidden: unwrap_impl(includeHidden), level: unwrap_impl(level), name: unwrap_impl(name), pressed: unwrap_impl(pressed), selected: unwrap_impl(selected))) end
def get_by_test_id(testId)
**Details**
```
page.get_by_test_id("directions").click()
```python sync
You can locate the element by it's test id:
```
```html
Consider the following DOM structure.
**Usage**
Locate element by the test id.
def get_by_test_id(testId) wrap_impl(@impl.get_by_test_id(unwrap_impl(testId))) end
def get_by_text(text, exact: nil)
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.
**Details**
```
page.get_by_text(re.compile("^hello$", re.IGNORECASE))
# Matches second
page.get_by_text(re.compile("Hello"))
# Matches both
page.get_by_text("Hello", exact=True)
# Matches second
page.get_by_text("Hello world")
# Matches first
page.get_by_text("world")
# Matches
```python sync
You can locate by text substring, exact string, or a regular expression:
```
```html
Consider the following DOM structure:
**Usage**
See also [`method: Locator.filter`] that allows to match by another criteria, like an accessible role, and then filter by the text content.
Allows locating elements that contain given text.
def get_by_text(text, exact: nil) wrap_impl(@impl.get_by_text(unwrap_impl(text), exact: unwrap_impl(exact))) end
def get_by_title(text, exact: nil)
expect(page.get_by_title("Issues count")).to_have_text("25 issues")
```python sync
You can check the issues count after locating it by the title text:
```
25 issues
```html
Consider the following DOM structure.
**Usage**
Allows locating elements by their title attribute.
def get_by_title(text, exact: nil) wrap_impl(@impl.get_by_title(unwrap_impl(text), exact: unwrap_impl(exact))) end
def last
def last wrap_impl(@impl.last) end
def locator(
The method finds an element matching the specified selector in the locator's subtree. It also accepts filter options, similar to [`method: Locator.filter`] method.
def locator( selectorOrLocator, has: nil, hasNot: nil, hasNotText: nil, hasText: nil) wrap_impl(@impl.locator(unwrap_impl(selectorOrLocator), has: unwrap_impl(has), hasNot: unwrap_impl(hasNot), hasNotText: unwrap_impl(hasNotText), hasText: unwrap_impl(hasText))) end
def nth(index)
def nth(index) wrap_impl(@impl.nth(unwrap_impl(index))) end