Class: Playwright::FrameLocator
- Inherits:
-
PlaywrightApi
- Object
- PlaywrightApi
- Playwright::FrameLocator
- Defined in:
- lib/playwright_api/frame_locator.rb
Overview
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.
“‘python sync locator = page.frame_locator(“my-frame”).locator(“text=Submit”) 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.
“‘python sync # Throws if there are several frames in DOM: page.frame_locator(’.result-frame’).locator(‘button’).click()
# Works because we explicitly tell locator to pick the first frame: page.frame_locator(‘.result-frame’).first.locator(‘button’).click() “‘
**Converting Locator to FrameLocator**
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:
“‘python sync frameLocator = locator.frame_locator(“:scope”); “`
Instance Method Summary collapse
-
#first ⇒ Object
Returns locator to the first matching frame.
-
#frame_locator(selector) ⇒ Object
When working with iframes, you can create a frame locator that will enter the iframe and allow selecting elements in that iframe.
-
#last ⇒ Object
Returns locator to the last matching frame.
-
#locator(selector, has: nil, hasText: nil) ⇒ Object
The method finds an element matching the specified selector in the FrameLocator’s subtree.
-
#nth(index) ⇒ Object
Returns locator to the n-th matching frame.
Methods inherited from PlaywrightApi
Constructor Details
This class inherits a constructor from Playwright::PlaywrightApi
Instance Method Details
#first ⇒ Object
Returns locator to the first matching frame.
35 36 37 |
# File 'lib/playwright_api/frame_locator.rb', line 35 def first wrap_impl(@impl.first) end |
#frame_locator(selector) ⇒ Object
When working with iframes, you can create a frame locator that will enter the iframe and allow selecting elements in that iframe.
41 42 43 |
# File 'lib/playwright_api/frame_locator.rb', line 41 def frame_locator(selector) wrap_impl(@impl.frame_locator(unwrap_impl(selector))) end |
#last ⇒ Object
Returns locator to the last matching frame.
46 47 48 |
# File 'lib/playwright_api/frame_locator.rb', line 46 def last wrap_impl(@impl.last) end |
#locator(selector, has: nil, hasText: nil) ⇒ Object
The method finds an element matching the specified selector in the FrameLocator’s subtree.
51 52 53 |
# File 'lib/playwright_api/frame_locator.rb', line 51 def locator(selector, has: nil, hasText: nil) wrap_impl(@impl.locator(unwrap_impl(selector), has: unwrap_impl(has), hasText: unwrap_impl(hasText))) end |
#nth(index) ⇒ Object
Returns locator to the n-th matching frame. It’s zero based, ‘nth(0)` selects the first frame.
56 57 58 |
# File 'lib/playwright_api/frame_locator.rb', line 56 def nth(index) wrap_impl(@impl.nth(unwrap_impl(index))) end |