View Source Playwright.Frame (playwright v1.44.0-alpha.4)
At any point of time, Playwright.Page
exposes its current frame tree via
the Playwright.Page.main_frame/1
and Playwright.Frame.child_frames/1
functions.
A Frame
instance lifecycle is governed by three events, dispatched on the
Playwright.Page
resource:
Page event: :frame_attached
- fired when the frame gets attached to the page. A Frame can be attached to the page only once.Page event: :frame_navigated
- fired when the frame commits navigation to a different URL.Page event: :frame_detached
- fired when the frame gets detached from the page. A Frame can be detached from the page only once.
Summary
Types
%Playwright.Frame{}
Functions
Clicks an element matching param: selector
, performing the following steps
Double clicks an element matching selector.
Dispatches the param: type
event on the param: selector
element.
Returns the return value of expression
.
Returns the return value of expression
.
!!!
Returns the return value of expression
as a Playwright.JSHandle
.
!!!
Fills a form field or contenteditable
element with text.
Fetches an element with param: selector
and focuses it.
Returns element attribute value. !!!
Allows locating elements that contain given text.
Hovers over an element matching param: selector
.
Optional callback implementation for Playwright.SDK.ChannelOwner.init/2
.
param: key
can specify the intended keyboardEvent.key
value or a single character for which to generate the text.
Returns the Playwright.ElementHandle
pointing to the frame element.
Returns the list of Playwright.ElementHandle
pointing to the frame elements.
Selects one or more options from a <select>
element.
Returns
:ok
Arguments
key/name | type | description | |
---|---|---|---|
html | param | binary() | HTML markup to assign to the page. |
:timeout | option | number() | Maximum operation time in milliseconds. Pass 0 to disable timeout. The default value can be changed by using the Playwright.BrowserContext.set_default_navigation_timeout/2 , Playwright.BrowserContext.set_default_timeout/2 , Playwright.Page.set_default_navigation_timeout/2 or Playwright.Page.set_default_timeout/ functions. (default: 30 seconds) |
Returns the page title.
Waits for the required load state to be reached.
Returns when element specified by selector satisfies state option.
Types
@type evaluation_argument() :: any()
@type expression() :: binary()
@type options() :: map()
@type serializable() :: any()
@type t() :: %Playwright.Frame{ guid: term(), initializer: term(), listeners: term(), load_states: term(), parent: term(), session: term(), type: term(), url: term() }
%Playwright.Frame{}
Functions
Clicks an element matching param: selector
, performing the following steps:
- Find an element matching
param: selector
. If there is none, wait until a matching element is attached to the DOM. - Wait for "actionability (guide)" checks on the matched element, unless
option: force
option is set. If the element is detached during the checks, the whole action is retried. - Scroll the element into view if needed.
- Use
Playwright.Page.Mouse
to click the center of the element, or the specifiedoption: position
. - Wait for initiated navigations to either succeed or fail, unless
option: :no_wait_after
option is set.
When all steps combined have not finished during the specified
option: timeout
, /click/3
raises a TimeoutError
. Passing zero for
option: timeout
disables this.
Double clicks an element matching selector.
Performs the following steps:
- Find an element matching
param: selector
. If there is none, wait until a matching element is attached to the DOM. - Wait for actionability checks on the matched element, unless
option: force
is set. If the element is detached during the checks, the whole action is retried. - Scroll the element into view if needed.
- Use
Page.Mouse
to double click in the center of the element, or the specifiedoption: position
. - Wait for initiated navigations to either succeed or fail, unless
option: no_wait_after
is set. Note that if the first click of thedblclick/3
triggers a navigation event, the call will throw.
When all steps combined have not finished during the specified
option: timeout
, throws a TimeoutError
. Passing timeout: 0
disables
this.
NOTE
dblclick/3
dispatches twoclick
events and a singledblclick
event.
Returns
:ok
Arguments
key/name | type | description | |
---|---|---|---|
selector | param | binary() | A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used. See "working with selectors (guide)" for more details. |
:button | option | :left , :right or :middle | (default: :left) |
:delay | option | number() | Time to wait between keydown and keyup in milliseconds. (default: 0) |
:force | option | boolean() | Whether to bypass the actionability checks. (default: false) |
:modifiers | option | [:alt, :control, :meta, :shift] | Modifier keys to press. Ensures that only these modifiers are pressed during the operation, and then restores current modifiers back. If not specified, currently pressed modifiers are used. |
:no_wait_after | option | boolean() | Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You can opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as navigating to inaccessible pages. (default: false) |
:position | option | %{x: x, y: y} | A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of the element. |
:strict | option | boolean() | When true, the call requires selector to resolve to a single element. If given selector resolves to more then one element, the call throws an exception. |
:timeout | option | number() | Maximum time in milliseconds. Pass 0 to disable timeout. The default value can be changed by using the Playwright.BrowserContext.set_default_timeout/2 or Playwright.Page.set_default_timeout/2 functions. (default: 30 seconds) |
:trial | option | boolean() | When set, this call only performs the actionability checks and skips the action. Useful to wait until the element is ready for the action without performing it. (default: false) |
dispatch_event(frame, selector, type, event_init \\ nil, options \\ %{})
View Source@spec dispatch_event(t(), binary(), binary(), evaluation_argument(), options()) :: :ok
Dispatches the param: type
event on the param: selector
element.
Regardless of the visibility state of the element, the event is dispatched.
Under the hood, creates an instance of an event based on the given type,
initializes it with the param: event_init
properties and dispatches it on
the element.
Events are composed, cancelable and bubble by default.
The param: event_init
is event-specific. Please refer to the events
documentation for the lists of initial properties:
Example
Dispatch a 'click' event on the element. This is equivalent to calling
Playwright.ElementHandle.click/2
:
Frame.dispatch_event(frame, "button#submit", :click)
Specify a Playwright.JSHandle
as the property value to be passed into the
event:
data_transfer = Frame.evaluate_handle(frame, "new DataTransfer()")
Frame.dispatch_event(frame, "#source", :dragstart, { "dataTransfer": data_transfer })
Returns
:ok
Arguments
key/name | type | description | |
---|---|---|---|
selector | param | binary() | A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used. See "working with selectors (guide)" for more details. |
type | param | atom() or binary() | DOM event type: :click , :dragstart , etc. |
event_init | param | evaluation_argument() | Optional event-specific initialization properties. |
:strict | option | boolean() | When true, the call requires selector to resolve to a single element. If given selector resolves to more then one element, the call throws an exception. |
:timeout | option | number() | Maximum time in milliseconds. Pass 0 to disable timeout. The default value can be changed by using the Playwright.BrowserContext.set_default_timeout/2 or Playwright.Page.set_default_timeout/2 functions. (default: 30 seconds) |
eval_on_selector(frame, selector, expression, arg \\ nil, options \\ %{})
View SourceReturns the return value of expression
.
!!!
@spec evaluate(t(), expression(), any()) :: :ok
Returns the return value of expression
.
!!!
@spec evaluate_handle(t(), expression(), any()) :: serializable()
Returns the return value of expression
as a Playwright.JSHandle
.
!!!
Fills a form field or contenteditable
element with text.
Waits for an element matching param: selector
, waits for "actionability
checks", focuses the element, fills it and triggers an input event after
filling.
If the target element is not an <input>
, <textarea>
or contenteditable
element, this function raises an error. However, if the element is inside the
<label>
element that has an associated control, the control will be filled
instead.
NOTE
- Pass an empty string to clear the input field.
- To send fine-grained keyboard events, use
Playwright.Frame.type/4
.
Returns
:ok
Arguments
key/name | type | description | |
---|---|---|---|
selector | param | binary() | A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used. See "working with selectors (guide)" for more details. |
value | param | binary() | Value to fill for the <input> , <textarea> or [contenteditable] element |
:force | option | boolean() | Whether to bypass the actionability checks. (default: false) |
:no_wait_after | option | boolean() | Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You can opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as navigating to inaccessible pages. (default: false) |
:strict | option | boolean() | When true, the call requires selector to resolve to a single element. If given selector resolves to more then one element, the call throws an exception. |
:timeout | option | number() | Maximum time in milliseconds. Pass 0 to disable timeout. The default value can be changed by using the Playwright.BrowserContext.set_default_timeout/2 or Playwright.Page.set_default_timeout/2 functions. (default: 30 seconds) |
Fetches an element with param: selector
and focuses it.
If no element matches the selector, waits until a matching element appears in the DOM.
Returns
:ok
Arguments
key/name | type | description | |
---|---|---|---|
selector | param | binary() | A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used. See "working with selectors (guide)" for more details. |
:strict | option | boolean() | When true, the call requires selector to resolve to a single element. If given selector resolves to more then one element, the call throws an exception. |
:timeout | option | number() | Maximum time in milliseconds. Pass 0 to disable timeout. The default value can be changed by using the Playwright.BrowserContext.set_default_timeout/2 or Playwright.Page.set_default_timeout/2 functions. (default: 30 seconds) |
Returns element attribute value. !!!
@spec get_by_text(t(), binary(), %{optional(:exact) => boolean()}) :: Playwright.Locator.t() | nil
Allows locating elements that contain given text.
Arguments
key/name | type | description | |
---|---|---|---|
text | param | binary() | Text to locate the element for. |
:exact | option | boolean() | Whether to find an exact match: case-sensitive and whole-string. Default to false. Ignored when locating by a regular expression. Note that exact match still trims whitespace. |
@spec goto(t(), binary(), options()) :: Playwright.Response.t() | nil | {:error, term()}
!!!
Hovers over an element matching param: selector
.
Performs the following steps:
- Find an element matching
param: selector
. If there is none, wait until a matching element is attached to the DOM. - Wait for actionability checks on the matched element, unless
option: force
option is set. If the element is detached during the checks, the whole action is retried. - Scroll the element into view if needed.
- Use
Page.Mouse
to hover over the center of the element, or the specifiedoption: position
. - Wait for initiated navigations to either succeed or fail, unless
option: no_wait_after
is set.
When all steps combined have not finished during the specified option: timeout
,
throws a TimeoutError
. Passing 0
timeout disables this.
Returns
:ok
Arguments
key/name | type | description | |
---|---|---|---|
selector | param | binary() | A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used. See "working with selectors (guide)" for more details. |
:force | option | boolean() | Whether to bypass the actionability checks. (default: false) |
:modifiers | option | [:alt, :control, :meta, :shift] | Modifier keys to press. Ensures that only these modifiers are pressed during the operation, and then restores current modifiers back. If not specified, currently pressed modifiers are used. |
:no_wait_after | option | boolean() | Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You can opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as navigating to inaccessible pages. (default: false) |
:position | option | %{x: x, y: y} | A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of the element. |
:strict | option | boolean() | When true, the call requires selector to resolve to a single element. If given selector resolves to more then one element, the call throws an exception. |
:timeout | option | number() | Maximum time in milliseconds. Pass 0 to disable timeout. The default value can be changed by using the Playwright.BrowserContext.set_default_timeout/2 or Playwright.Page.set_default_timeout/2 functions. (default: 30 seconds) |
:trial | option | boolean() | When set, this call only performs the actionability checks and skips the action. Useful to wait until the element is ready for the action without performing it. (default: false) |
Optional callback implementation for Playwright.SDK.ChannelOwner.init/2
.
If implemented, the callback will receive:
- The newly created "channel owner" struct.
- The
:initializer
received from the Playwright browser server.
The implementation has the option of "patching" the struct as stored in the catalog, and/or binding event handlers.
Example
def init(%{session: session} = owner, _initializer) do
Channel.bind(session, {:guid, owner.guid}, :close, fn event ->
Logger.warning("Closing #{inspect(event.target)}")
end)
{:ok, %{owner | version: "1.2.3"}}
end
Returns
{:ok, struct()}
Arguments
key/name | type | description | |
---|---|---|---|
owner | param | struct() | The newly created channel owner (resource). |
initializer | param | struct() | The initializer received from with the channel owner instance was derived. |
@spec locator(t(), binary()) :: Playwright.Locator.t()
param: key
can specify the intended keyboardEvent.key
value or a single character for which to generate the text.
A superset of the
param: key
values can be found on MDN.
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.
The following modification shortcuts are also supported: Shift
, Control
,
Alt
, Meta
, ShiftLeft
.
Holding down Shift
will type the text that corresponds to the param: key
in the upper case.
If param: 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"
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.
Returns
- :ok
Arguments
key/name | type | description | |
---|---|---|---|
selector | param | binary() | A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used. See "working with selectors (guide)" for more details. |
key | param | binary() | Name of the key to press or a character to generate, such as ArrowLeft or a . |
:delay | option | number() | Time to wait between keydown and keyup in milliseconds. (default: 0) |
:no_wait_after | option | boolean() | Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You can opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as navigating to inaccessible pages. (default: false) |
:strict | option | boolean() | When true, the call requires selector to resolve to a single element. If given selector resolves to more then one element, the call throws an exception. |
:timeout | option | number() | Maximum time in milliseconds. Pass 0 to disable timeout. The default value can be changed by using the Playwright.BrowserContext.set_default_timeout/2 or Playwright.Page.set_default_timeout/2 functions. (default: 30 seconds) |
@spec query_selector(t(), binary(), map()) :: Playwright.ElementHandle.t() | nil | {:error, :timeout}
Returns the Playwright.ElementHandle
pointing to the frame element.
The function finds an element matching the specified selector within the
frame. See "working with selectors (guide)" for more details. If no elements
match the selector, returns nil
.
Returns
Playwright.ElementHandle.t()
nil
Arguments
key/name | type | description | |
---|---|---|---|
selector | param | binary() | A selector to query for. See "working with selectors (guide)" for more details. |
strict | option | boolean() | When true, the call requires selector to resolve to a single element. If the given selector resolves to more then one element, the call raises an error. |
@spec query_selector_all(t(), binary(), map()) :: [Playwright.ElementHandle.t()]
Returns the list of Playwright.ElementHandle
pointing to the frame elements.
The method finds all elements matching the specified selector within the frame. See "working with selectors (guide)" for more details.
If no elements match the selector, returns an empty List
.
Returns
[Playwright.ElementHandle.t()]
Arguments
key/name | type | description | |
---|---|---|---|
selector | param | binary() | A selector to query for. See "working with selectors (guide)" for more details. |
Selects one or more options from a <select>
element.
Performs the following steps:
- Waits for an element matching
param: selector
- Waits for actionability checks
- Waits until all specified options are present in the
<select>
element - Selects those options
If the target element is not a <select>
element, raises an error. However,
if the element is inside the <label>
element that has an associated control,
the control will be used instead.
Returns the list of option values that have been successfully selected.
Triggers a change and input event once all the provided options have been selected.
Example
# single selection matching the value
Frame.select_option(frame, "select#colors", "blue")
# single selection matching both the label
Frame.select_option(frame, "select#colors", %{label: "blue"})
# multiple selection
Frame.select_option(frame, "select#colors", %{value: ["red", "green", "blue"]})
Returns
[binary()]
Arguments
key/name | type | description | |
---|---|---|---|
selector | param | binary() | A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used. See "working with selectors (guide)" for more details. |
values | param | any() | Options to select. |
:force | option | boolean() | Whether to bypass the actionability checks. (default: false) |
:no_wait_after | option | boolean() | Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You can opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as navigating to inaccessible pages. (default: false) |
:strict | option | boolean() | When true, the call requires selector to resolve to a single element. If given selector resolves to more then one element, the call throws an exception. |
:timeout | option | number() | Maximum time in milliseconds. Pass 0 to disable timeout. The default value can be changed by using the Playwright.BrowserContext.set_default_timeout/2 or Playwright.Page.set_default_timeout/2 functions. (default: 30 seconds) |
On values
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 equivalent to %{value: "string"}
.
Option is considered matching if all specified properties match.
value <binary>
Matches byoption.value
.(optional)
.label <binary>
Matches byoption.label
.(optional)
.index <number>
Matches by the index.(optional)
.
Returns
:ok
Arguments
key/name | type | description | |
---|---|---|---|
html | param | binary() | HTML markup to assign to the page. |
:timeout | option | number() | Maximum operation time in milliseconds. Pass 0 to disable timeout. The default value can be changed by using the Playwright.BrowserContext.set_default_navigation_timeout/2 , Playwright.BrowserContext.set_default_timeout/2 , Playwright.Page.set_default_navigation_timeout/2 or Playwright.Page.set_default_timeout/ functions. (default: 30 seconds) |
Returns Playwright.ElementHandle.text_content/1
Returns
binary() | nil
Arguments
key/name | type | description | |
---|---|---|---|
selector | param | binary() | A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used. See "working with selectors (guide)" for more details. |
:strict | option | boolean() | When true, the call requires selector to resolve to a single element. If given selector resolves to more then one element, the call throws an exception. |
:timeout | option | number() | Maximum time in milliseconds. Pass 0 to disable timeout. The default value can be changed by using the Playwright.BrowserContext.set_default_timeout/2 or Playwright.Page.set_default_timeout/2 functions. (default: 30 seconds) |
Returns the page title.
Returns
binary()
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 the current document has already reached the required state, resolves immediately.
@spec wait_for_selector(t(), binary(), map()) :: Playwright.ElementHandle.t() | {:error, Playwright.SDK.Channel.Error.t()}
Returns when element specified by selector satisfies state option.
FIXME: the following is NOT TRUE... Returns nil
if waiting for a hidden or detached element.