Page provides methods to interact with a single tab in a Browser, or an
extension background page in Chromium. One Browser
instance might have multiple Page instances.
This example creates a page, navigates it to a URL, and then saves a screenshot:
# Or Playwright.chromium/1 or Playwright.firefox/1.
browser = Playwright.webkit(playwright) |> BrowserType.launch!()
context = Browser.new_context!(browser)
page = BrowserContext.new_page!(context)
Page.goto!(page, "https://example.com")
Page.screenshot!(page, path: "screenshot.png")
Browser.close!(browser)The Page class emits various events (described below) which can be handled with Playwright.Page.on/3, Playwright.Page.once/3 or Playwright.Page.off/3.
This example logs a message for a single page load event:
Page.once(page, :load, fn _page -> IO.puts("Page loaded!") end)To unsubscribe from events use the remove_listener/3 method:
log_request = fn intercepted_request ->
IO.puts("A request was made: #{Request.url(intercepted_request)}")
end
Page.on(page, :request, log_request)
# Sometime later...
Page.remove_listener(page, :request, log_request)Since Playwright 1.8.
The examples alias the modules they use (alias Playwright.{Locator, Page}).
Events
:close
Emitted when the page closes.
:console
Emitted when JavaScript within the page calls one of console API methods, e.g. console.log or console.dir.
The arguments passed into console.log are available on the ConsoleMessage event handler argument.
Usage
Page.on(page, :console, fn msg ->
values = for arg <- ConsoleMessage.args(msg), do: JSHandle.json_value!(arg)
IO.puts(inspect(values))
end)
Page.evaluate!(page, "() => console.log('hello', 5, { foo: 'bar' })"):crash
Emitted when the page crashes. Browser pages might crash if they try to allocate too much memory. When the page crashes, ongoing and subsequent operations will fail.
The most common way to deal with crashes is to catch an exception:
try do
# Crash might happen during a click.
Page.click!(page, "button")
# Or while waiting for an event.
Page.wait_for_event!(page, :popup)
rescue
e ->
# When the page crashes, exception message contains "crash".
Exception.message(e)
end:dialog
Emitted when a JavaScript dialog appears, such as alert, prompt, confirm or beforeunload. Listener must either Playwright.Dialog.accept/2 or Playwright.Dialog.dismiss/1 the dialog - otherwise the page will freeze waiting for the dialog, and actions like click will never finish.
Usage
Page.on(page, :dialog, &Dialog.accept!/1)Note
When no Page.on(:dialog) or BrowserContext.on(:dialog) listeners are present, all dialogs are automatically dismissed.
:dialog_closed
Since Playwright 1.63. Emitted when a JavaScript dialog has been closed, either by Playwright.Dialog.accept/2, by Playwright.Dialog.dismiss/1, or manually by the user in the headed browser.
:dom_content_loaded
Since Playwright 1.9. Emitted when the JavaScript DOMContentLoaded
event is dispatched.
:download
Emitted when attachment download started. User can access basic file operations on downloaded content via the passed
Download instance.
:file_chooser
Since Playwright 1.9. Emitted when a file chooser is supposed to appear, such as after clicking the <input type=file>. Playwright can
respond to it via setting the input files using Playwright.FileChooser.set_files/3 that can be uploaded after that.
Page.on(page, :file_chooser, fn file_chooser ->
FileChooser.set_files!(file_chooser, Path.join(__DIR__, "/tmp/myfile.pdf"))
end):frame_attached
Since Playwright 1.9. Emitted when a frame is attached.
:frame_detached
Since Playwright 1.9. Emitted when a frame is detached.
:frame_navigated
Since Playwright 1.9. Emitted when a frame is navigated to a new url.
:load
Emitted when the JavaScript load event is dispatched.
:page_error
Since Playwright 1.9. Emitted when an uncaught exception happens within the page.
# Log all uncaught errors to the terminal
Page.on(page, :page_error, fn exception ->
IO.puts("Uncaught exception: \"#{Exception.message(exception)}\"")
end)
# Navigate to a page with an exception.
Page.goto!(page, ~s{data:text/html,<script>throw new Error("Test")</script>}):popup
Emitted when the page opens a new tab or window. This event is emitted in addition to the
BrowserContext.on(:page), but only for popups relevant to this page.
The earliest moment that page is available is when it has navigated to the initial url. For example, when opening a
popup with window.open('http://example.com'), this event will fire when the network request to "http://example.com" is
done and its response has started loading in the popup. If you would like to route/listen to this network request, use Playwright.BrowserContext.route/4 and BrowserContext.on(:request) respectively instead of similar methods on the Page.
# Start waiting for popup before clicking: a promise, awaited after.
popup_promise = Page.wait_for_event(page, :popup)
Page.get_by_text(page, "open the popup") |> Locator.click!()
popup = Promise.await!(popup_promise)
IO.puts(Page.evaluate!(popup, "location.href"))Note
Use Playwright.Page.wait_for_load_state/3 to wait until the page gets to a particular state (you should not need it in most
cases).
:request
Emitted when a page issues a request. The Request object is read-only. In order to intercept and mutate requests, see
Playwright.Page.route/4 or Playwright.BrowserContext.route/4.
:request_failed
Since Playwright 1.9. Emitted when a request fails, for example by timing out.
Page.on(page, :request_failed, fn request ->
IO.puts(Request.url(request) <> " " <> Request.failure(request).errorText)
end)Note
HTTP Error responses, such as 404 or 503, are still successful responses from HTTP standpoint, so request will complete
with Page.on(:request_finished) event and not with Page.on(:request_failed). A request will only be considered
failed when the client cannot get an HTTP response from the server, e.g. due to network error net::ERR_FAILED.
:request_finished
Since Playwright 1.9. Emitted when a request finishes successfully after downloading the response body. For a successful response, the
sequence of events is request, response and requestfinished.
:response
Emitted when Response status and headers are received for a request. For a successful response, the sequence of events
is request, response and requestfinished.
:web_socket
Since Playwright 1.9. Emitted when WebSocket request is sent.
:worker
Emitted when a dedicated WebWorker is spawned by the page.
Summary
Types
Options of add_init_script/4, see its docs.
Options of add_locator_handler/4, see its docs.
Options of add_script_tag/2, see its docs.
Options of add_style_tag/2, see its docs.
Options of aria_snapshot_json/2, see its docs.
Options of aria_snapshot/2, see its docs.
Options of check/3, see its docs.
Options of click/3, see its docs.
Options of close/2, see its docs.
Options of console_messages/2, see its docs.
Options of content/2, see its docs.
Options of dblclick/3, see its docs.
Options of dispatch_event/5, see its docs.
Options of drag_and_drop/4, see its docs.
Options of emulate_media/2, see its docs.
Options of evaluate_handle/4, see its docs.
Options of evaluate/4, see its docs.
An event name, see the module docs.
Options of expect_console_message/3, see its docs.
Options of expect_download/3, see its docs.
Options of expect_event/4, see its docs.
Options of expect_file_chooser/3, see its docs.
Options of expect_navigation/3, see its docs.
Options of expect_popup/3, see its docs.
Options of expect_request_finished/3, see its docs.
Options of expect_request/4, see its docs.
Options of expect_response/4, see its docs.
Options of expect_websocket/3, see its docs.
Options of expect_worker/3, see its docs.
Options of fill/4, see its docs.
Options of focus/3, see its docs.
Options of get_attribute/4, see its docs.
Options of get_by_alt_text/3, see its docs.
Options of get_by_label/3, see its docs.
Options of get_by_placeholder/3, see its docs.
Options of get_by_role/3, see its docs.
Options of get_by_text/3, see its docs.
Options of get_by_title/3, see its docs.
Options of go_back/2, see its docs.
Options of go_forward/2, see its docs.
Options of goto/3, see its docs.
Options of hover/3, see its docs.
Options of inner_html/3, see its docs.
Options of inner_text/3, see its docs.
Options of input_value/3, see its docs.
Options of is_checked/3, see its docs.
Options of is_disabled/3, see its docs.
Options of is_editable/3, see its docs.
Options of is_enabled/3, see its docs.
Options of is_hidden/3, see its docs.
Options of is_visible/3, see its docs.
Options of locator/3, see its docs.
Options of page_errors/2, see its docs.
Options of pdf/2, see its docs.
Options of press/4, see its docs.
Options of query_selector/3, see its docs.
Options of reload/2, see its docs.
Options of remove_all_listeners/3, see its docs.
Options of route_from_har/3, see its docs.
Options of route/4, see its docs.
Options of screenshot/2, see its docs.
Options of select_option/4, see its docs.
Options of set_checked/4, see its docs.
Options of set_content/3, see its docs.
Options of set_input_files/4, see its docs.
A Page handle. Compare handles with ==, their fields are internal.
Options of tap/3, see its docs.
Options of text_content/3, see its docs.
Options of type/4, see its docs.
Options of uncheck/3, see its docs.
Options of unroute_all/2, see its docs.
Options of wait_for_event/3, see its docs.
Options of wait_for_function/4, see its docs.
Options of wait_for_load_state/3, see its docs.
Options of wait_for_navigation/2, see its docs.
Options of wait_for_request/3, see its docs.
Options of wait_for_response/3, see its docs.
Options of wait_for_selector/3, see its docs.
Options of wait_for_url/3, see its docs.
Functions
Adds a script which would be evaluated in one of the following scenarios
Like add_init_script/4, but returns the value and raises on error.
When testing a web page, sometimes unexpected overlays like a "Sign up" dialog appear and block actions you want to automate, e.g. clicking a button. These overlays don't always show up in the same way or at the same time, making them tricky to handle in automated tests.
Like add_locator_handler/4, but returns the value and raises on error.
Adds a <script> tag into the page with the desired url or content. Returns the added tag when the script's onload
fires or when the script content was injected into frame.
Like add_script_tag/2, but returns the value and raises on error.
Adds a <link rel="stylesheet"> tag into the page with the desired url or a <style type="text/css"> tag with the
content. Returns the added tag when the stylesheet's onload fires or when the CSS content was injected into frame.
Like add_style_tag/2, but returns the value and raises on error.
Captures the aria snapshot of the page. Read more about aria snapshots.
Like aria_snapshot/2, but returns the value and raises on error.
Captures the aria snapshot of the page as a free form JSON object.
Returns the same tree as Playwright.Page.aria_snapshot/2, serialized as a JSON value instead of YAML markup.
See Playwright.Locator.aria_snapshot_json/2 for the details of the format.
Like aria_snapshot_json/2, but returns the value and raises on error.
Brings page to front (activates tab).
Like bring_to_front/1, but returns the value and raises on error.
Cancels an ongoing Playwright.Page.pick_locator/1 call by deactivating pick locator mode.
If no pick locator mode is active, this method is a no-op.
Like cancel_pick_locator/1, but returns the value and raises on error.
This method checks an element matching selector by performing the following steps
Like check/3, but returns the value and raises on error.
Clears all stored console messages from this page. Subsequent calls to Playwright.Page.console_messages/2 will only return messages logged after the clear.
Like clear_console_messages/1, but returns the value and raises on error.
Clears all stored page errors from this page. Subsequent calls to Playwright.Page.page_errors/2 will only return errors thrown after the clear.
Like clear_page_errors/1, but returns the value and raises on error.
This method clicks an element matching selector by performing the following steps
Like click/3, but returns the value and raises on error.
Playwright has ability to mock clock and passage of time.
If :run_before_unload is false, does not run any unload handlers and waits for the page to be closed. If
:run_before_unload is true the method will run unload handlers, but will not wait for the page to close.
Like close/2, but returns the value and raises on error.
Returns up to (currently) 200 last console messages from this page. See Page.on(:console) for more details.
Like console_messages/2, but returns the value and raises on error.
Gets the full HTML contents of the page, including the doctype.
Like content/2, but returns the value and raises on error.
Get the browser context that the page belongs to.
This method double clicks an element matching selector by performing the following steps
Like dblclick/3, but returns the value and raises on error.
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().
Like dispatch_event/5, but returns the value and raises on error.
This method drags the source element to the target element.
It will first move to the source element, perform a mousedown,
then move to the target element and perform a mouseup.
Like drag_and_drop/4, but returns the value and raises on error.
This method changes the CSS media type through the :media option, and/or the 'prefers-colors-scheme' media feature, using the :color_scheme option.
Like emulate_media/2, but returns the value and raises on error.
The method finds an element matching the specified selector within the page and passes it as a first argument to
expression. If no elements match the selector, the method fails. Returns the value of
expression.
Like eval_on_selector/4, but returns the value and raises on error.
The method finds all elements matching the specified selector within the page and passes an array of matched elements as
a first argument to expression. Returns the result of expression invocation.
Like eval_on_selector_all/4, but returns the value and raises on error.
Returns the value of the expression invocation.
Like evaluate/4, but returns the value and raises on error.
Returns the value of the expression invocation as a JSHandle.
Like evaluate_handle/4, but returns the value and raises on error.
Performs action and waits for a ConsoleMessage to be logged by in the page. If predicate is provided, it passes
ConsoleMessage value into the :predicate function and waits for predicate(message) to return a truthy value.
Will fail if the page is closed before the Page.on(:console) event is fired.
Like expect_console_message/3, but returns the value and raises on error.
Like expect_download/3, but returns the value and raises on error.
Waits for event to fire and passes its value into the predicate function. Returns when the predicate returns truthy value. Will fail if the page is closed before the event is fired. Returns the event data value.
Like expect_event/4, but returns the value and raises on error.
Performs action and waits for a new FileChooser to be created. If predicate is provided, it passes
FileChooser value into the :predicate function and waits for predicate(fileChooser) to return a truthy value.
Will fail if the page is closed before the file chooser is opened.
Like expect_file_chooser/3, but returns the value and raises on error.
Waits for the main frame navigation and returns the main resource response. In case of multiple redirects, the navigation
returns the response of the last redirect. In case of navigation to a different anchor or navigation due to
History API usage, the navigation returns nil.
Like expect_navigation/3, but returns the value and raises on error.
Performs action and waits for a popup Page. If predicate is provided, it passes
Popup value into the :predicate function and waits for predicate(page) to return a truthy value.
Will fail if the page is closed before the popup event is fired.
Like expect_popup/3, but returns the value and raises on error.
Waits for the matching request and returns it. See waiting for event for more details about events.
Like expect_request/4, but returns the value and raises on error.
Performs action and waits for a Request to finish loading. If predicate is provided, it passes
Request value into the :predicate function and waits for predicate(request) to return a truthy value.
Will fail if the page is closed before the Page.on(:request_finished) event is fired.
Like expect_request_finished/3, but returns the value and raises on error.
Returns the matched response. See waiting for event for more details about events.
Like expect_response/4, but returns the value and raises on error.
Like expect_websocket/3, but returns the value and raises on error.
Like expect_worker/3, but returns the value and raises on error.
The method adds a function called name on the window object of every frame in this page. When called, the
function executes callback and returns a Promise which resolves to the return value of callback.
If callback returns a Playwright.Promise, it is awaited.
Like expose_binding/3, but returns the value and raises on error.
The method adds a function called name on the window object of every frame in the page. When called, the
function executes callback and returns a Promise which resolves to the return value of callback.
Like expose_function/3, but returns the value and raises on error.
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.
Like fill/4, but returns the value and raises on error.
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.
Like focus/3, but returns the value and raises on error.
Returns frame matching the specified criteria. Either name or url must be specified.
When working with iframes, you can create a frame locator that will enter the iframe and allow selecting elements in that iframe.
An array of all frames attached to the page.
Returns element attribute value.
Like get_attribute/4, but returns the value and raises on error.
Allows locating elements by their alt text.
Allows locating input elements by the text of the associated <label> or aria-labelledby element, or by the aria-label attribute.
Allows locating input elements by the placeholder text.
Locate element by its aria ref. Refs like [ref=e2] are reported by Playwright.Page.aria_snapshot/2 when called with
the "ai" mode, and resolve against the latest snapshot taken in the element's frame.
Allows locating elements by their ARIA role, ARIA attributes and accessible name.
Locate element by the test id.
Allows locating elements that contain given text.
Allows locating elements by their title attribute.
Returns the main resource response. In case of multiple redirects, the navigation returns the response of the
last redirect. If cannot go back, returns nil.
Like go_back/2, but returns the value and raises on error.
Returns the main resource response. In case of multiple redirects, the navigation returns the response of the
last redirect. If cannot go forward, returns nil.
Like go_forward/2, but returns the value and raises on error.
Returns the main resource response. In case of multiple redirects, the navigation returns the first non-redirect response.
Like goto/3, but returns the value and raises on error.
Hide all locator highlight overlays previously added by Playwright.Locator.highlight/2 on this page.
Like hide_highlight/1, but returns the value and raises on error.
This method hovers over an element matching selector by performing the following steps
Like hover/3, but returns the value and raises on error.
Returns element.innerHTML.
Like inner_html/3, but returns the value and raises on error.
Returns element.innerText.
Like inner_text/3, but returns the value and raises on error.
Returns input.value for the selected <input> or <textarea> or <select> element.
Like input_value/3, but returns the value and raises on error.
Returns whether the element is checked. Fails if the element is not a checkbox or radio input.
Like is_checked/3, but returns the value and raises on error.
Indicates that the page has been closed.
Returns whether the element is disabled, the opposite of enabled.
Like is_disabled/3, but returns the value and raises on error.
Returns whether the element is editable.
Like is_editable/3, but returns the value and raises on error.
Returns whether the element is enabled.
Like is_enabled/3, but returns the value and raises on error.
Returns whether the element is hidden, the opposite of visible. selector that does not match any elements is considered hidden.
Like is_hidden/3, but returns the value and raises on error.
Returns whether the element is visible. selector that does not match any elements is considered not visible.
Like is_visible/3, but returns the value and raises on error.
Since Playwright 1.8.
Provides access to the page's localStorage for the current origin. See WebStorage.
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.
The page's main frame. Page is guaranteed to have a main frame which persists during navigations.
Since Playwright 1.8.
Returns the opener for popup pages and nil for others. If the opener has been closed already the returns nil.
Like opener/1, but returns the value and raises on error.
Returns up to (currently) 200 last page errors from this page. See Page.on(:page_error) for more details.
Like page_errors/2, but returns the value and raises on error.
Pauses script execution. Playwright will stop executing the script and wait for the user to either press the 'Resume'
button in the page overlay or to call playwright.resume() in the DevTools console.
Like pause/1, but returns the value and raises on error.
Returns the PDF buffer.
Like pdf/2, but returns the value and raises on error.
Enters pick locator mode where hovering over page elements highlights them and shows the corresponding locator.
Once the user clicks an element, the mode is deactivated and the Locator for the picked element is returned.
Like pick_locator/1, but returns the value and raises on error.
Focuses the element, and then uses Playwright.Keyboard.down/2 and Playwright.Keyboard.up/2.
Like press/4, but returns the value and raises on error.
The method finds an element matching the specified selector within the page. If no elements match the selector, the
return value is nil. To wait for an element on the page, use Playwright.Locator.wait_for/2.
Like query_selector/3, but returns the value and raises on error.
The method finds all elements matching the specified selector within the page. If no elements match the selector, the
return value is [].
Like query_selector_all/2, but returns the value and raises on error.
This method reloads the current page, in the same way as if the user had triggered a browser refresh. Returns the main resource response. In case of multiple redirects, the navigation returns the response of the last redirect.
Like reload/2, but returns the value and raises on error.
Removes all the listeners of the given type (or all registered listeners if no type given). Allows to wait for running listeners to complete or to ignore subsequent errors from these listeners.
Like remove_all_listeners/3, but returns the value and raises on error.
Removes all locator handlers added by Playwright.Page.add_locator_handler/4 for a specific locator.
Like remove_locator_handler/2, but returns the value and raises on error.
API testing helper associated with this page. This method returns the same instance as
Playwright.BrowserContext.request/1 on the page's context. See Playwright.BrowserContext.request/1 for more details.
Request the page to perform garbage collection. Note that there is no guarantee that all unreachable objects will be collected.
Like request_gc/1, but returns the value and raises on error.
Returns up to (currently) 100 last network request from this page. See Page.on(:request) for more details.
Like requests/1, but returns the value and raises on error.
Routing provides the capability to modify network requests that are made by a page.
Like route/4, but returns the value and raises on error.
If specified the network requests that are made in the page will be served from the HAR file. Read more about Replaying from HAR.
Like route_from_har/3, but returns the value and raises on error.
This method allows to modify websocket connections that are made by the page.
Like route_web_socket/3, but returns the value and raises on error.
Screencast object associated with this page.
Returns the buffer with the captured screenshot.
Like screenshot/2, but returns the value and raises on error.
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.
Like select_option/4, but returns the value and raises on error.
Provides access to the page's sessionStorage for the current origin. See WebStorage.
This method checks or unchecks an element matching selector by performing the following steps
Like set_checked/4, but returns the value and raises on error.
This method internally calls document.write(), inheriting all its specific characteristics and behaviors.
Like set_content/3, but returns the value and raises on error.
This setting will change the default maximum navigation time for the following methods and related shortcuts
This setting will change the default maximum time for all the methods accepting timeout option.
The extra HTTP headers will be sent with every request the page initiates.
Like set_extra_http_headers/2, but returns the value and raises on error.
Sets the value of the file input to these file paths or files. If some of the files are relative paths, then they
are resolved relative to the current working directory. For empty array, clears the selected files.
For inputs with a [webkitdirectory] attribute, only a single directory path is supported.
Like set_input_files/4, but returns the value and raises on error.
In the case of multiple pages in a single browser, each page can have its own viewport size. However,
Playwright.Browser.new_context/2 allows to set viewport size (and more) for all pages in the context at once.
Like set_viewport_size/2, but returns the value and raises on error.
This method taps an element matching selector by performing the following steps
Like tap/3, but returns the value and raises on error.
Returns element.textContent.
Like text_content/3, but returns the value and raises on error.
Returns the page's title.
Like title/1, but returns the value and raises on error.
Since Playwright 1.8.
Sends a keydown, keypress/input, and keyup event for each character in the text. Playwright.Page.type/4 can be used to send
fine-grained keyboard events. To fill values in form fields, use Playwright.Page.fill/4.
Like type/4, but returns the value and raises on error.
This method unchecks an element matching selector by performing the following steps
Like uncheck/3, but returns the value and raises on error.
Removes a route created with Playwright.Page.route/4. When handler is not specified, removes all routes for
the url.
Like unroute/3, but returns the value and raises on error.
Removes all routes created with Playwright.Page.route/4 and Playwright.Page.route_from_har/3.
Like unroute_all/2, but returns the value and raises on error.
Since Playwright 1.8.
Video object associated with this page. Can be used to access the video file when using the :record_video context option.
Since Playwright 1.8.
Waits for event to fire and passes its value into the predicate function. Returns when the predicate returns truthy value. Will fail if the page is closed before the event is fired. Returns the event data value.
Like wait_for_event/3, but awaits the promise: Playwright.Promise.await!(wait_for_event(...)), the value or a raise.
Returns when the expression returns a truthy value. It returns a JSHandle of the truthy value.
Like wait_for_function/4, but returns the value and raises on error.
Returns when the required load state has been reached.
Like wait_for_load_state/3, but returns the value and raises on error.
Waits for the main frame navigation and returns the main resource response. In case of multiple redirects, the navigation
returns the response of the last redirect. In case of navigation to a different anchor or navigation due to
History API usage, the navigation returns nil.
Like wait_for_navigation/2, but awaits the promise: Playwright.Promise.await!(wait_for_navigation(...)), the value or a raise.
Waits for the matching request and returns it. See waiting for event for more details about events.
Like wait_for_request/3, but awaits the promise: Playwright.Promise.await!(wait_for_request(...)), the value or a raise.
Returns the matched response. See waiting for event for more details about events.
Like wait_for_response/3, but awaits the promise: Playwright.Promise.await!(wait_for_response(...)), the value or a raise.
Returns when element specified by selector satisfies :state option. Returns nil if waiting for hidden or
detached.
Like wait_for_selector/3, but returns the value and raises on error.
Waits for the given timeout in milliseconds. It rejects :infinity.
Like wait_for_timeout/2, but returns the value and raises on error.
Waits for the main frame to navigate to the given URL.
Like wait_for_url/3, but returns the value and raises on error.
Tools that the main frame registers through the experimental WebMCP browser API. Shortcut for Playwright.Frame.webmcp/1 of Playwright.Page.main_frame/1, see WebMCP for details.
This method returns all of the dedicated WebWorkers associated with the page.
Events
Adds an event listener for event, see the module docs for the events.
Removes an event listener added by on/3 or add_listener/3.
Adds an event listener for event, see the module docs for the events.
Adds an event listener that is removed after it is triggered once. See on/3.
Adds an event listener for event, see the module docs for the events.
Removes an event listener added by on/3 or add_listener/3.
Types
@type add_init_script_options() :: [{:expose_functions, boolean()}] | %{optional(:expose_functions) => boolean()}
Options of add_init_script/4, see its docs.
@type add_locator_handler_options() :: [no_wait_after: boolean(), times: integer()] | %{optional(:no_wait_after) => boolean(), optional(:times) => integer()}
Options of add_locator_handler/4, see its docs.
@type add_script_tag_options() :: [content: String.t(), path: String.t(), type: String.t(), url: String.t()] | %{ optional(:content) => String.t(), optional(:path) => String.t(), optional(:type) => String.t(), optional(:url) => String.t() }
Options of add_script_tag/2, see its docs.
@type add_style_tag_options() :: [content: String.t(), path: String.t(), url: String.t()] | %{ optional(:content) => String.t(), optional(:path) => String.t(), optional(:url) => String.t() }
Options of add_style_tag/2, see its docs.
@type aria_snapshot_json_options() :: [ boxes: boolean(), depth: integer(), mode: :ai | :default, signal: Playwright.AbortSignal.t(), timeout: number() | :infinity ] | %{ optional(:boxes) => boolean(), optional(:depth) => integer(), optional(:mode) => :ai | :default, optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity }
Options of aria_snapshot_json/2, see its docs.
@type aria_snapshot_options() :: [ boxes: boolean(), depth: integer(), mode: :ai | :default, signal: Playwright.AbortSignal.t(), timeout: number() | :infinity ] | %{ optional(:boxes) => boolean(), optional(:depth) => integer(), optional(:mode) => :ai | :default, optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity }
Options of aria_snapshot/2, see its docs.
@type check_options() :: [ force: boolean(), no_wait_after: boolean(), position: %{x: number(), y: number()}, scroll: :auto | :none, signal: Playwright.AbortSignal.t(), strict: boolean(), timeout: number() | :infinity, trial: boolean() ] | %{ optional(:force) => boolean(), optional(:no_wait_after) => boolean(), optional(:position) => %{x: number(), y: number()}, optional(:scroll) => :auto | :none, optional(:signal) => Playwright.AbortSignal.t(), optional(:strict) => boolean(), optional(:timeout) => number() | :infinity, optional(:trial) => boolean() }
Options of check/3, see its docs.
@type click_options() :: [ button: :left | :right | :middle, click_count: integer(), delay: number(), force: boolean(), modifiers: [:alt | :control | :control_or_meta | :meta | :shift], no_wait_after: boolean(), position: %{x: number(), y: number()}, scroll: :auto | :none, signal: Playwright.AbortSignal.t(), strict: boolean(), timeout: number() | :infinity, trial: boolean() ] | %{ optional(:button) => :left | :right | :middle, optional(:click_count) => integer(), optional(:delay) => number(), optional(:force) => boolean(), optional(:modifiers) => [ :alt | :control | :control_or_meta | :meta | :shift ], optional(:no_wait_after) => boolean(), optional(:position) => %{x: number(), y: number()}, optional(:scroll) => :auto | :none, optional(:signal) => Playwright.AbortSignal.t(), optional(:strict) => boolean(), optional(:timeout) => number() | :infinity, optional(:trial) => boolean() }
Options of click/3, see its docs.
@type close_options() :: [reason: String.t(), run_before_unload: boolean()] | %{ optional(:reason) => String.t(), optional(:run_before_unload) => boolean() }
Options of close/2, see its docs.
@type console_messages_options() ::
[{:filter, :all | :since_navigation}]
| %{optional(:filter) => :all | :since_navigation}
Options of console_messages/2, see its docs.
@type content_options() :: [{:include_shadow, boolean()}] | %{optional(:include_shadow) => boolean()}
Options of content/2, see its docs.
@type dblclick_options() :: [ button: :left | :right | :middle, delay: number(), force: boolean(), modifiers: [:alt | :control | :control_or_meta | :meta | :shift], no_wait_after: boolean(), position: %{x: number(), y: number()}, scroll: :auto | :none, signal: Playwright.AbortSignal.t(), strict: boolean(), timeout: number() | :infinity, trial: boolean() ] | %{ optional(:button) => :left | :right | :middle, optional(:delay) => number(), optional(:force) => boolean(), optional(:modifiers) => [ :alt | :control | :control_or_meta | :meta | :shift ], optional(:no_wait_after) => boolean(), optional(:position) => %{x: number(), y: number()}, optional(:scroll) => :auto | :none, optional(:signal) => Playwright.AbortSignal.t(), optional(:strict) => boolean(), optional(:timeout) => number() | :infinity, optional(:trial) => boolean() }
Options of dblclick/3, see its docs.
@type dispatch_event_options() :: [ signal: Playwright.AbortSignal.t(), strict: boolean(), timeout: number() | :infinity ] | %{ optional(:signal) => Playwright.AbortSignal.t(), optional(:strict) => boolean(), optional(:timeout) => number() | :infinity }
Options of dispatch_event/5, see its docs.
@type drag_and_drop_options() :: [ force: boolean(), no_wait_after: boolean(), scroll: :auto | :none, signal: Playwright.AbortSignal.t(), source_position: %{x: number(), y: number()}, steps: integer(), strict: boolean(), target_position: %{x: number(), y: number()}, timeout: number() | :infinity, trial: boolean() ] | %{ optional(:force) => boolean(), optional(:no_wait_after) => boolean(), optional(:scroll) => :auto | :none, optional(:signal) => Playwright.AbortSignal.t(), optional(:source_position) => %{x: number(), y: number()}, optional(:steps) => integer(), optional(:strict) => boolean(), optional(:target_position) => %{x: number(), y: number()}, optional(:timeout) => number() | :infinity, optional(:trial) => boolean() }
Options of drag_and_drop/4, see its docs.
@type emulate_media_options() ::
[
color_scheme: :null | :light | :dark | :no_preference,
contrast: :null | :no_preference | :more,
forced_colors: :null | :active | :none,
media: :null | :screen | :print,
reduced_motion: :null | :reduce | :no_preference
]
| %{
optional(:color_scheme) => :null | :light | :dark | :no_preference,
optional(:contrast) => :null | :no_preference | :more,
optional(:forced_colors) => :null | :active | :none,
optional(:media) => :null | :screen | :print,
optional(:reduced_motion) => :null | :reduce | :no_preference
}
Options of emulate_media/2, see its docs.
@type evaluate_handle_options() :: [{:expose_functions, boolean()}] | %{optional(:expose_functions) => boolean()}
Options of evaluate_handle/4, see its docs.
@type evaluate_options() :: [{:expose_functions, boolean()}] | %{optional(:expose_functions) => boolean()}
Options of evaluate/4, see its docs.
@type event() ::
:close
| :console
| :crash
| :dialog
| :dialog_closed
| :dom_content_loaded
| :download
| :file_chooser
| :frame_attached
| :frame_detached
| :frame_navigated
| :load
| :page_error
| :popup
| :request
| :request_failed
| :request_finished
| :response
| :web_socket
| :worker
An event name, see the module docs.
@type expect_console_message_options() :: [ predicate: (Playwright.ConsoleMessage.t() -> boolean()), timeout: number() | :infinity, signal: Playwright.AbortSignal.t() ] | %{ optional(:predicate) => (Playwright.ConsoleMessage.t() -> boolean()), optional(:timeout) => number() | :infinity, optional(:signal) => Playwright.AbortSignal.t() }
Options of expect_console_message/3, see its docs.
@type expect_download_options() :: [ predicate: (Playwright.Download.t() -> boolean()), timeout: number() | :infinity, signal: Playwright.AbortSignal.t() ] | %{ optional(:predicate) => (Playwright.Download.t() -> boolean()), optional(:timeout) => number() | :infinity, optional(:signal) => Playwright.AbortSignal.t() }
Options of expect_download/3, see its docs.
@type expect_event_options() :: [ predicate: fun(), timeout: number() | :infinity, signal: Playwright.AbortSignal.t() ] | %{ optional(:predicate) => fun(), optional(:timeout) => number() | :infinity, optional(:signal) => Playwright.AbortSignal.t() }
Options of expect_event/4, see its docs.
@type expect_file_chooser_options() :: [ predicate: (Playwright.FileChooser.t() -> boolean()), timeout: number() | :infinity, signal: Playwright.AbortSignal.t() ] | %{ optional(:predicate) => (Playwright.FileChooser.t() -> boolean()), optional(:timeout) => number() | :infinity, optional(:signal) => Playwright.AbortSignal.t() }
Options of expect_file_chooser/3, see its docs.
@type expect_popup_options() :: [ predicate: (t() -> boolean()), timeout: number() | :infinity, signal: Playwright.AbortSignal.t() ] | %{ optional(:predicate) => (t() -> boolean()), optional(:timeout) => number() | :infinity, optional(:signal) => Playwright.AbortSignal.t() }
Options of expect_popup/3, see its docs.
@type expect_request_finished_options() :: [ predicate: (Playwright.Request.t() -> boolean()), timeout: number() | :infinity, signal: Playwright.AbortSignal.t() ] | %{ optional(:predicate) => (Playwright.Request.t() -> boolean()), optional(:timeout) => number() | :infinity, optional(:signal) => Playwright.AbortSignal.t() }
Options of expect_request_finished/3, see its docs.
@type expect_request_options() :: [timeout: number() | :infinity, signal: Playwright.AbortSignal.t()] | %{ optional(:timeout) => number() | :infinity, optional(:signal) => Playwright.AbortSignal.t() }
Options of expect_request/4, see its docs.
@type expect_response_options() :: [timeout: number() | :infinity, signal: Playwright.AbortSignal.t()] | %{ optional(:timeout) => number() | :infinity, optional(:signal) => Playwright.AbortSignal.t() }
Options of expect_response/4, see its docs.
@type expect_websocket_options() :: [ predicate: (Playwright.WebSocket.t() -> boolean()), timeout: number() | :infinity, signal: Playwright.AbortSignal.t() ] | %{ optional(:predicate) => (Playwright.WebSocket.t() -> boolean()), optional(:timeout) => number() | :infinity, optional(:signal) => Playwright.AbortSignal.t() }
Options of expect_websocket/3, see its docs.
@type expect_worker_options() :: [ predicate: (Playwright.Worker.t() -> boolean()), timeout: number() | :infinity, signal: Playwright.AbortSignal.t() ] | %{ optional(:predicate) => (Playwright.Worker.t() -> boolean()), optional(:timeout) => number() | :infinity, optional(:signal) => Playwright.AbortSignal.t() }
Options of expect_worker/3, see its docs.
@type fill_options() :: [ force: boolean(), no_wait_after: boolean(), signal: Playwright.AbortSignal.t(), strict: boolean(), timeout: number() | :infinity ] | %{ optional(:force) => boolean(), optional(:no_wait_after) => boolean(), optional(:signal) => Playwright.AbortSignal.t(), optional(:strict) => boolean(), optional(:timeout) => number() | :infinity }
Options of fill/4, see its docs.
@type focus_options() :: [ signal: Playwright.AbortSignal.t(), strict: boolean(), timeout: number() | :infinity ] | %{ optional(:signal) => Playwright.AbortSignal.t(), optional(:strict) => boolean(), optional(:timeout) => number() | :infinity }
Options of focus/3, see its docs.
@type get_attribute_options() :: [ signal: Playwright.AbortSignal.t(), strict: boolean(), timeout: number() | :infinity ] | %{ optional(:signal) => Playwright.AbortSignal.t(), optional(:strict) => boolean(), optional(:timeout) => number() | :infinity }
Options of get_attribute/4, see its docs.
Options of get_by_alt_text/3, see its docs.
Options of get_by_label/3, see its docs.
Options of get_by_placeholder/3, see its docs.
@type get_by_role_options() :: [ checked: boolean(), description: String.t() | Regex.t() | Playwright.RegExp.t(), disabled: boolean(), exact: boolean(), expanded: boolean(), include_hidden: boolean(), level: integer(), name: String.t() | Regex.t() | Playwright.RegExp.t(), pressed: boolean(), selected: boolean() ] | %{ optional(:checked) => boolean(), optional(:description) => String.t() | Regex.t() | Playwright.RegExp.t(), optional(:disabled) => boolean(), optional(:exact) => boolean(), optional(:expanded) => boolean(), optional(:include_hidden) => boolean(), optional(:level) => integer(), optional(:name) => String.t() | Regex.t() | Playwright.RegExp.t(), optional(:pressed) => boolean(), optional(:selected) => boolean() }
Options of get_by_role/3, see its docs.
Options of get_by_text/3, see its docs.
Options of get_by_title/3, see its docs.
@type go_back_options() :: [ signal: Playwright.AbortSignal.t(), timeout: number() | :infinity, wait_until: :load | :domcontentloaded | :networkidle | :commit ] | %{ optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity, optional(:wait_until) => :load | :domcontentloaded | :networkidle | :commit }
Options of go_back/2, see its docs.
@type go_forward_options() :: [ signal: Playwright.AbortSignal.t(), timeout: number() | :infinity, wait_until: :load | :domcontentloaded | :networkidle | :commit ] | %{ optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity, optional(:wait_until) => :load | :domcontentloaded | :networkidle | :commit }
Options of go_forward/2, see its docs.
@type goto_options() :: [ referer: String.t(), signal: Playwright.AbortSignal.t(), timeout: number() | :infinity, wait_until: :load | :domcontentloaded | :networkidle | :commit ] | %{ optional(:referer) => String.t(), optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity, optional(:wait_until) => :load | :domcontentloaded | :networkidle | :commit }
Options of goto/3, see its docs.
@type hover_options() :: [ force: boolean(), modifiers: [:alt | :control | :control_or_meta | :meta | :shift], no_wait_after: boolean(), position: %{x: number(), y: number()}, scroll: :auto | :none, signal: Playwright.AbortSignal.t(), strict: boolean(), timeout: number() | :infinity, trial: boolean() ] | %{ optional(:force) => boolean(), optional(:modifiers) => [ :alt | :control | :control_or_meta | :meta | :shift ], optional(:no_wait_after) => boolean(), optional(:position) => %{x: number(), y: number()}, optional(:scroll) => :auto | :none, optional(:signal) => Playwright.AbortSignal.t(), optional(:strict) => boolean(), optional(:timeout) => number() | :infinity, optional(:trial) => boolean() }
Options of hover/3, see its docs.
@type inner_html_options() :: [ signal: Playwright.AbortSignal.t(), strict: boolean(), timeout: number() | :infinity ] | %{ optional(:signal) => Playwright.AbortSignal.t(), optional(:strict) => boolean(), optional(:timeout) => number() | :infinity }
Options of inner_html/3, see its docs.
@type inner_text_options() :: [ signal: Playwright.AbortSignal.t(), strict: boolean(), timeout: number() | :infinity ] | %{ optional(:signal) => Playwright.AbortSignal.t(), optional(:strict) => boolean(), optional(:timeout) => number() | :infinity }
Options of inner_text/3, see its docs.
@type input_value_options() :: [ signal: Playwright.AbortSignal.t(), strict: boolean(), timeout: number() | :infinity ] | %{ optional(:signal) => Playwright.AbortSignal.t(), optional(:strict) => boolean(), optional(:timeout) => number() | :infinity }
Options of input_value/3, see its docs.
@type is_checked_options() :: [ signal: Playwright.AbortSignal.t(), strict: boolean(), timeout: number() | :infinity ] | %{ optional(:signal) => Playwright.AbortSignal.t(), optional(:strict) => boolean(), optional(:timeout) => number() | :infinity }
Options of is_checked/3, see its docs.
@type is_disabled_options() :: [ signal: Playwright.AbortSignal.t(), strict: boolean(), timeout: number() | :infinity ] | %{ optional(:signal) => Playwright.AbortSignal.t(), optional(:strict) => boolean(), optional(:timeout) => number() | :infinity }
Options of is_disabled/3, see its docs.
@type is_editable_options() :: [ signal: Playwright.AbortSignal.t(), strict: boolean(), timeout: number() | :infinity ] | %{ optional(:signal) => Playwright.AbortSignal.t(), optional(:strict) => boolean(), optional(:timeout) => number() | :infinity }
Options of is_editable/3, see its docs.
@type is_enabled_options() :: [ signal: Playwright.AbortSignal.t(), strict: boolean(), timeout: number() | :infinity ] | %{ optional(:signal) => Playwright.AbortSignal.t(), optional(:strict) => boolean(), optional(:timeout) => number() | :infinity }
Options of is_enabled/3, see its docs.
@type is_visible_options() :: [strict: boolean(), timeout: number() | :infinity] | %{ optional(:strict) => boolean(), optional(:timeout) => number() | :infinity }
Options of is_visible/3, see its docs.
@type locator_options() :: [ has: Playwright.Locator.t(), has_not: Playwright.Locator.t(), has_not_text: String.t() | Regex.t() | Playwright.RegExp.t(), has_text: String.t() | Regex.t() | Playwright.RegExp.t() ] | %{ optional(:has) => Playwright.Locator.t(), optional(:has_not) => Playwright.Locator.t(), optional(:has_not_text) => String.t() | Regex.t() | Playwright.RegExp.t(), optional(:has_text) => String.t() | Regex.t() | Playwright.RegExp.t() }
Options of locator/3, see its docs.
@type page_errors_options() ::
[{:filter, :all | :since_navigation}]
| %{optional(:filter) => :all | :since_navigation}
Options of page_errors/2, see its docs.
@type pdf_options() :: [ display_header_footer: boolean(), footer_template: String.t(), format: String.t(), header_template: String.t(), height: String.t() | number(), landscape: boolean(), margin: %{ optional(:top) => String.t() | number(), optional(:right) => String.t() | number(), optional(:bottom) => String.t() | number(), optional(:left) => String.t() | number() }, outline: boolean(), page_ranges: String.t(), path: String.t(), prefer_css_page_size: boolean(), print_background: boolean(), scale: number(), tagged: boolean(), width: String.t() | number() ] | %{ optional(:display_header_footer) => boolean(), optional(:footer_template) => String.t(), optional(:format) => String.t(), optional(:header_template) => String.t(), optional(:height) => String.t() | number(), optional(:landscape) => boolean(), optional(:margin) => %{ optional(:top) => String.t() | number(), optional(:right) => String.t() | number(), optional(:bottom) => String.t() | number(), optional(:left) => String.t() | number() }, optional(:outline) => boolean(), optional(:page_ranges) => String.t(), optional(:path) => String.t(), optional(:prefer_css_page_size) => boolean(), optional(:print_background) => boolean(), optional(:scale) => number(), optional(:tagged) => boolean(), optional(:width) => String.t() | number() }
Options of pdf/2, see its docs.
@type press_options() :: [ delay: number(), no_wait_after: boolean(), signal: Playwright.AbortSignal.t(), strict: boolean(), timeout: number() | :infinity ] | %{ optional(:delay) => number(), optional(:no_wait_after) => boolean(), optional(:signal) => Playwright.AbortSignal.t(), optional(:strict) => boolean(), optional(:timeout) => number() | :infinity }
Options of press/4, see its docs.
Options of query_selector/3, see its docs.
@type reload_options() :: [ signal: Playwright.AbortSignal.t(), timeout: number() | :infinity, wait_until: :load | :domcontentloaded | :networkidle | :commit ] | %{ optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity, optional(:wait_until) => :load | :domcontentloaded | :networkidle | :commit }
Options of reload/2, see its docs.
@type remove_all_listeners_options() ::
[{:behavior, :wait | :ignore_errors | :default}]
| %{optional(:behavior) => :wait | :ignore_errors | :default}
Options of remove_all_listeners/3, see its docs.
@type route_from_har_options() :: [ not_found: :abort | :fallback, update: boolean(), update_content: :embed | :attach, update_mode: :full | :minimal, url: String.t() | Regex.t() | Playwright.RegExp.t() ] | %{ optional(:not_found) => :abort | :fallback, optional(:update) => boolean(), optional(:update_content) => :embed | :attach, optional(:update_mode) => :full | :minimal, optional(:url) => String.t() | Regex.t() | Playwright.RegExp.t() }
Options of route_from_har/3, see its docs.
Options of route/4, see its docs.
@type screenshot_options() :: [ animations: :disabled | :allow, caret: :hide | :initial, clip: %{x: number(), y: number(), width: number(), height: number()}, full_page: boolean(), mask: [Playwright.Locator.t()], mask_color: String.t(), omit_background: boolean(), path: String.t(), quality: integer(), scale: :css | :device, signal: Playwright.AbortSignal.t(), style: String.t(), timeout: number() | :infinity, type: :png | :jpeg | :webp ] | %{ optional(:animations) => :disabled | :allow, optional(:caret) => :hide | :initial, optional(:clip) => %{ x: number(), y: number(), width: number(), height: number() }, optional(:full_page) => boolean(), optional(:mask) => [Playwright.Locator.t()], optional(:mask_color) => String.t(), optional(:omit_background) => boolean(), optional(:path) => String.t(), optional(:quality) => integer(), optional(:scale) => :css | :device, optional(:signal) => Playwright.AbortSignal.t(), optional(:style) => String.t(), optional(:timeout) => number() | :infinity, optional(:type) => :png | :jpeg | :webp }
Options of screenshot/2, see its docs.
@type select_option_options() :: [ force: boolean(), no_wait_after: boolean(), signal: Playwright.AbortSignal.t(), strict: boolean(), timeout: number() | :infinity ] | %{ optional(:force) => boolean(), optional(:no_wait_after) => boolean(), optional(:signal) => Playwright.AbortSignal.t(), optional(:strict) => boolean(), optional(:timeout) => number() | :infinity }
Options of select_option/4, see its docs.
@type set_checked_options() :: [ force: boolean(), no_wait_after: boolean(), position: %{x: number(), y: number()}, scroll: :auto | :none, signal: Playwright.AbortSignal.t(), strict: boolean(), timeout: number() | :infinity, trial: boolean() ] | %{ optional(:force) => boolean(), optional(:no_wait_after) => boolean(), optional(:position) => %{x: number(), y: number()}, optional(:scroll) => :auto | :none, optional(:signal) => Playwright.AbortSignal.t(), optional(:strict) => boolean(), optional(:timeout) => number() | :infinity, optional(:trial) => boolean() }
Options of set_checked/4, see its docs.
@type set_content_options() :: [ signal: Playwright.AbortSignal.t(), timeout: number() | :infinity, wait_until: :load | :domcontentloaded | :networkidle | :commit ] | %{ optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity, optional(:wait_until) => :load | :domcontentloaded | :networkidle | :commit }
Options of set_content/3, see its docs.
@type set_input_files_options() :: [ no_wait_after: boolean(), signal: Playwright.AbortSignal.t(), strict: boolean(), timeout: number() | :infinity ] | %{ optional(:no_wait_after) => boolean(), optional(:signal) => Playwright.AbortSignal.t(), optional(:strict) => boolean(), optional(:timeout) => number() | :infinity }
Options of set_input_files/4, see its docs.
@type t() :: %Playwright.Page{ conn: term(), guid: term(), initializer: term(), table: term(), type: term() }
A Page handle. Compare handles with ==, their fields are internal.
@type tap_options() :: [ force: boolean(), modifiers: [:alt | :control | :control_or_meta | :meta | :shift], no_wait_after: boolean(), position: %{x: number(), y: number()}, scroll: :auto | :none, signal: Playwright.AbortSignal.t(), strict: boolean(), timeout: number() | :infinity, trial: boolean() ] | %{ optional(:force) => boolean(), optional(:modifiers) => [ :alt | :control | :control_or_meta | :meta | :shift ], optional(:no_wait_after) => boolean(), optional(:position) => %{x: number(), y: number()}, optional(:scroll) => :auto | :none, optional(:signal) => Playwright.AbortSignal.t(), optional(:strict) => boolean(), optional(:timeout) => number() | :infinity, optional(:trial) => boolean() }
Options of tap/3, see its docs.
@type text_content_options() :: [ signal: Playwright.AbortSignal.t(), strict: boolean(), timeout: number() | :infinity ] | %{ optional(:signal) => Playwright.AbortSignal.t(), optional(:strict) => boolean(), optional(:timeout) => number() | :infinity }
Options of text_content/3, see its docs.
@type type_options() :: [ delay: number(), no_wait_after: boolean(), signal: Playwright.AbortSignal.t(), strict: boolean(), timeout: number() | :infinity ] | %{ optional(:delay) => number(), optional(:no_wait_after) => boolean(), optional(:signal) => Playwright.AbortSignal.t(), optional(:strict) => boolean(), optional(:timeout) => number() | :infinity }
Options of type/4, see its docs.
@type uncheck_options() :: [ force: boolean(), no_wait_after: boolean(), position: %{x: number(), y: number()}, scroll: :auto | :none, signal: Playwright.AbortSignal.t(), strict: boolean(), timeout: number() | :infinity, trial: boolean() ] | %{ optional(:force) => boolean(), optional(:no_wait_after) => boolean(), optional(:position) => %{x: number(), y: number()}, optional(:scroll) => :auto | :none, optional(:signal) => Playwright.AbortSignal.t(), optional(:strict) => boolean(), optional(:timeout) => number() | :infinity, optional(:trial) => boolean() }
Options of uncheck/3, see its docs.
@type unroute_all_options() ::
[{:behavior, :wait | :ignore_errors | :default}]
| %{optional(:behavior) => :wait | :ignore_errors | :default}
Options of unroute_all/2, see its docs.
@type wait_for_event_options() :: [ predicate: fun(), timeout: number() | :infinity, signal: Playwright.AbortSignal.t() ] | %{ optional(:predicate) => fun(), optional(:timeout) => number() | :infinity, optional(:signal) => Playwright.AbortSignal.t() }
Options of wait_for_event/3, see its docs.
@type wait_for_function_options() :: [ polling: number() | :raf, signal: Playwright.AbortSignal.t(), timeout: number() | :infinity ] | %{ optional(:polling) => number() | :raf, optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity }
Options of wait_for_function/4, see its docs.
@type wait_for_load_state_options() :: [signal: Playwright.AbortSignal.t(), timeout: number() | :infinity] | %{ optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity }
Options of wait_for_load_state/3, see its docs.
@type wait_for_request_options() :: [signal: Playwright.AbortSignal.t(), timeout: number() | :infinity] | %{ optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity }
Options of wait_for_request/3, see its docs.
@type wait_for_response_options() :: [signal: Playwright.AbortSignal.t(), timeout: number() | :infinity] | %{ optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity }
Options of wait_for_response/3, see its docs.
@type wait_for_selector_options() :: [ signal: Playwright.AbortSignal.t(), state: :attached | :detached | :visible | :hidden, strict: boolean(), timeout: number() | :infinity ] | %{ optional(:signal) => Playwright.AbortSignal.t(), optional(:state) => :attached | :detached | :visible | :hidden, optional(:strict) => boolean(), optional(:timeout) => number() | :infinity }
Options of wait_for_selector/3, see its docs.
@type wait_for_url_options() :: [ signal: Playwright.AbortSignal.t(), timeout: number() | :infinity, wait_until: :load | :domcontentloaded | :networkidle | :commit ] | %{ optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity, optional(:wait_until) => :load | :domcontentloaded | :networkidle | :commit }
Options of wait_for_url/3, see its docs.
Functions
@spec add_init_script( t(), String.t() | %{optional(:path) => String.t(), optional(:content) => String.t()}, term() | nil, add_init_script_options() ) :: {:ok, Playwright.Disposable.t()} | {:error, Playwright.error()}
Adds a script which would be evaluated in one of the following scenarios:
- Whenever the page is navigated.
- Whenever the child frame is attached or navigated. In this case, the script is evaluated in the context of the newly attached frame.
The script is evaluated after the document was created but before any of its scripts were run. This is useful to amend
the JavaScript environment, e.g. to seed Math.random.
Usage
An example of overriding Math.random before the page loads:
// preload.js
Math.random = () => 42;# In your playwright script, assuming the preload.js file is in same directory
Page.add_init_script!(page, %{path: "./preload.js"})Page.add_init_script!(page, "mock => { window.mock = mock; }", mock)Note
The order of evaluation of multiple scripts installed via Playwright.BrowserContext.add_init_script/4 and
Playwright.Page.add_init_script/4 is not defined.
Since Playwright 1.8.
Arguments
script- Script to be evaluated in the page.:path- Path to the JavaScript file. Ifpathis a relative path, then it is resolved relative to the current working directory. Optional.:content- Raw script content. Optional.
arg- Optional argument to pass toscript(only supported when passing a function).
Options
:expose_functions(boolean/0) - Since Playwright 1.62. When set totrue, functions passed insideargare exposed in the page and can be called from the init script. Calling one returns aPromiseof its result. Under the hood, each function is exposed viaPlaywright.Page.expose_function/3, so it is technically accessible from all frames of the page. Unlike functions passed toPlaywright.Page.evaluate/4, functions passed to an init script are exposed in every new document, so they survive navigations. Defaults tofalse, in which case functions are not serializable and are silently dropped.
@spec add_init_script!( t(), String.t() | %{optional(:path) => String.t(), optional(:content) => String.t()}, term() | nil, add_init_script_options() ) :: Playwright.Disposable.t()
Like add_init_script/4, but returns the value and raises on error.
@spec add_locator_handler( t(), Playwright.Locator.t(), (Playwright.Locator.t() -> term()), add_locator_handler_options() ) :: :ok | {:error, Playwright.error()}
When testing a web page, sometimes unexpected overlays like a "Sign up" dialog appear and block actions you want to automate, e.g. clicking a button. These overlays don't always show up in the same way or at the same time, making them tricky to handle in automated tests.
This method lets you set up a special function, called a handler, that activates when it detects that overlay is visible. The handler's job is to remove the overlay, allowing your test to continue as if the overlay wasn't there.
Things to keep in mind:
- When an overlay is shown predictably, we recommend explicitly waiting for it in your test and dismissing it as a part of your normal test flow, instead of using
Playwright.Page.add_locator_handler/4. - Playwright checks for the overlay every time before executing or retrying an action that requires an actionability check, or before performing an auto-waiting assertion check. When overlay is visible, Playwright calls the handler first, and then proceeds with the action/assertion. Note that the handler is only called when you perform an action/assertion - if the overlay becomes visible but you don't perform any actions, the handler will not be triggered.
- After executing the handler, Playwright will ensure that overlay that triggered the handler is not visible anymore. You can opt-out of this behavior with
:no_wait_after. - The execution time of the handler counts towards the timeout of the action/assertion that executed the handler. If your handler takes too long, it might cause timeouts.
- You can register multiple handlers. However, only a single handler will be running at a time. Make sure the actions within a handler don't depend on another handler.
Warning
Running the handler will alter your page state mid-test. For example it will change the currently focused element and move the mouse. Make sure that actions that run after the handler are self-contained and do not rely on the focus and mouse state being unchanged.
For example, consider a test that calls Playwright.Locator.focus/2 followed by Playwright.Keyboard.press/3. If your handler clicks a button between these two actions, the focused element most likely will be wrong, and key press will happen on the unexpected element. Use Playwright.Locator.press/3 instead to avoid this problem.
Another example is a series of mouse actions, where Playwright.Mouse.move/4 is followed by Playwright.Mouse.down/2. Again, when the handler runs between these two actions, the mouse position will be wrong during the mouse down. Prefer self-contained actions like Playwright.Locator.click/2 that do not rely on the state being unchanged by a handler.
Usage
An example that closes a "Sign up to the newsletter" dialog when it appears:
# Setup the handler.
Page.add_locator_handler!(page, Page.get_by_text(page, "Sign up to the newsletter"), fn ->
Page.get_by_role(page, :button, name: "No thanks") |> Locator.click!()
end)
# Write the test as usual.
Page.goto!(page, "https://example.com")
Page.get_by_role(page, :button, name: "Start here") |> Locator.click!()An example that skips the "Confirm your security details" page when it is shown:
# Setup the handler.
Page.add_locator_handler!(page, Page.get_by_text(page, "Confirm your security details"), fn ->
Page.get_by_role(page, :button, name: "Remind me later") |> Locator.click!()
end)
# Write the test as usual.
Page.goto!(page, "https://example.com")
Page.get_by_role(page, :button, name: "Start here") |> Locator.click!()An example with a custom callback on every actionability check. It uses a <body> locator that is always visible, so the handler is called before every actionability check. It is important to specify :no_wait_after, because the handler does not hide the <body> element.
# Setup the handler.
Page.add_locator_handler!(
page,
Page.locator(page, "body"),
fn -> Page.evaluate!(page, "() => window.removeObstructionsForTestIfNeeded()") end,
no_wait_after: true
)
# Write the test as usual.
Page.goto!(page, "https://example.com")
Page.get_by_role(page, :button, name: "Start here") |> Locator.click!()Handler takes the original locator as an argument. You can also automatically remove the handler after a number of invocations by setting :times:
Page.add_locator_handler!(page, Page.get_by_label(page, "Close"), &Locator.click!/1, times: 1)Since Playwright 1.42.
Arguments
locator- Locator that triggers the handler.handler- Function that should be run oncelocatorappears. This function should get rid of the element that blocks actions like click.
Options
:no_wait_after(boolean/0) - Since Playwright 1.44. By default, after calling the handler Playwright will wait until the overlay becomes hidden, and only then Playwright will continue with the action/assertion that triggered the handler. This option allows to opt-out of this behavior, so that overlay can stay visible after the handler has run.:times(integer/0) - Since Playwright 1.44. Specifies the maximum number of times this handler should be called. Unlimited by default.
@spec add_locator_handler!( t(), Playwright.Locator.t(), (Playwright.Locator.t() -> term()), add_locator_handler_options() ) :: :ok
Like add_locator_handler/4, but returns the value and raises on error.
@spec add_script_tag(t(), add_script_tag_options()) :: {:ok, Playwright.ElementHandle.t()} | {:error, Playwright.error()}
Adds a <script> tag into the page with the desired url or content. Returns the added tag when the script's onload
fires or when the script content was injected into frame.
Since Playwright 1.8.
Options
:content(String.t/0) - Raw JavaScript content to be injected into frame.:path(String.t/0) - Path to the JavaScript file to be injected into frame. If:pathis a relative path, then it is resolved relative to the current working directory.:type(String.t/0) - Script type. Use 'module' in order to load a JavaScript ES6 module. See script for more details.:url(String.t/0) - URL of a script to be added.
@spec add_script_tag!(t(), add_script_tag_options()) :: Playwright.ElementHandle.t()
Like add_script_tag/2, but returns the value and raises on error.
@spec add_style_tag(t(), add_style_tag_options()) :: {:ok, Playwright.ElementHandle.t()} | {:error, Playwright.error()}
Adds a <link rel="stylesheet"> tag into the page with the desired url or a <style type="text/css"> tag with the
content. Returns the added tag when the stylesheet's onload fires or when the CSS content was injected into frame.
Since Playwright 1.8.
Options
:content(String.t/0) - Raw CSS content to be injected into frame.:path(String.t/0) - Path to the CSS file to be injected into frame. If:pathis a relative path, then it is resolved relative to the current working directory.:url(String.t/0) - URL of the<link>tag.
@spec add_style_tag!(t(), add_style_tag_options()) :: Playwright.ElementHandle.t()
Like add_style_tag/2, but returns the value and raises on error.
@spec aria_snapshot(t(), aria_snapshot_options()) :: {:ok, String.t()} | {:error, Playwright.error()}
Captures the aria snapshot of the page. Read more about aria snapshots.
Since Playwright 1.59.
Options
:boxes(boolean/0) - Since Playwright 1.60. Whentrue, appends each element's bounding box as[box=x,y,width,height]to the snapshot. Coordinates are relative to the viewport, in CSS pixels, as returned byElement.getBoundingClientRect(). Defaults tofalse.:depth(integer/0) - When specified, limits the depth of the snapshot.:mode(:ai|:default) - When set to:ai, returns a snapshot optimized for AI consumption: including element references like[ref=e2]and snapshots of<iframe>s. Defaults to:default.:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. Allows to cancel the operation using anAbortSignal. If the signal is aborted, the operation will be aborted and fail. Note that providing a signal does not disable the default timeout, which can be changed usingPlaywright.BrowserContext.set_default_timeout/2orPlaywright.Page.set_default_timeout/2; passtimeout: 0to disable the timeout entirely.In Elixir, a
Playwright.AbortSignal(Playwright.AbortController.signal/1).:timeout(number/0|:infinity) - Maximum time in milliseconds. Defaults to30000(30 seconds). Pass0to disable timeout. The default value can be changed by using thePlaywright.BrowserContext.set_default_timeout/2orPlaywright.Page.set_default_timeout/2methods.In Elixir,
:infinityis the same as0: no timeout.
@spec aria_snapshot!(t(), aria_snapshot_options()) :: String.t()
Like aria_snapshot/2, but returns the value and raises on error.
@spec aria_snapshot_json(t(), aria_snapshot_json_options()) :: {:ok, term()} | {:error, Playwright.error()}
Captures the aria snapshot of the page as a free form JSON object.
Returns the same tree as Playwright.Page.aria_snapshot/2, serialized as a JSON value instead of YAML markup.
See Playwright.Locator.aria_snapshot_json/2 for the details of the format.
Since Playwright 1.63.
Options
:boxes(boolean/0) - Whentrue, includes each element's bounding box as aboxproperty withx,y,widthandheight. Coordinates are relative to the viewport, in CSS pixels, as returned byElement.getBoundingClientRect(). Defaults tofalse.:depth(integer/0) - When specified, limits the depth of the snapshot.:mode(:ai|:default) - When set to:ai, returns a snapshot optimized for AI consumption: including element references like[ref=e2]and snapshots of<iframe>s. Defaults to:default.:signal(Playwright.AbortSignal.t/0) - Allows to cancel the operation using anAbortSignal. If the signal is aborted, the operation will be aborted and fail. Note that providing a signal does not disable the default timeout, which can be changed usingPlaywright.BrowserContext.set_default_timeout/2orPlaywright.Page.set_default_timeout/2; passtimeout: 0to disable the timeout entirely.In Elixir, a
Playwright.AbortSignal(Playwright.AbortController.signal/1).:timeout(number/0|:infinity) - Maximum time in milliseconds. Defaults to30000(30 seconds). Pass0to disable timeout. The default value can be changed by using thePlaywright.BrowserContext.set_default_timeout/2orPlaywright.Page.set_default_timeout/2methods.In Elixir,
:infinityis the same as0: no timeout.
@spec aria_snapshot_json!(t(), aria_snapshot_json_options()) :: term()
Like aria_snapshot_json/2, but returns the value and raises on error.
@spec bring_to_front(t()) :: :ok | {:error, Playwright.error()}
Brings page to front (activates tab).
Since Playwright 1.8.
@spec bring_to_front!(t()) :: :ok
Like bring_to_front/1, but returns the value and raises on error.
@spec cancel_pick_locator(t()) :: :ok | {:error, Playwright.error()}
Cancels an ongoing Playwright.Page.pick_locator/1 call by deactivating pick locator mode.
If no pick locator mode is active, this method is a no-op.
Since Playwright 1.59.
@spec cancel_pick_locator!(t()) :: :ok
Like cancel_pick_locator/1, but returns the value and raises on error.
@spec check(t(), String.t(), check_options()) :: :ok | {:error, Playwright.error()}
This method checks an element matching selector by performing the following steps:
- Find an element matching
selector. If there is none, wait until a matching element is attached to the DOM. - Ensure that matched element is a checkbox or a radio input. If not, this method fails. If the element is already checked, this method returns immediately.
- Wait for actionability checks on the matched element, unless
:forceoption 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/1to click in the center of the element. - Ensure that the element is now checked. If not, this method fails.
When all steps combined have not finished during the specified :timeout, this method fails with a
TimeoutError. Passing zero timeout disables this.
Discouraged
Use locator-based Playwright.Locator.check/2 instead. Read more about locators.
Since Playwright 1.8.
Arguments
selector- A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.
Options
:force(boolean/0) - Whether to bypass the actionability checks. Defaults tofalse.:no_wait_after(boolean/0) - This option has no effect.:position(map/0) - Since Playwright 1.11. A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of the element.:x:y
:scroll(:auto|:none) - Since Playwright 1.62. Controls whether Playwright scrolls the element into view before performing the action. Defaults to:auto, which scrolls the element into view when necessary, including scrolling nested scrollable containers. When set to:none, Playwright does not scroll the element and the action fails if the element is not already in the viewport. This is useful to assert that an element is reachable by the user without additional scrolling.:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. Allows to cancel the operation using anAbortSignal. If the signal is aborted, the operation will be aborted and fail. Note that providing a signal does not disable the default timeout, which can be changed usingPlaywright.BrowserContext.set_default_timeout/2orPlaywright.Page.set_default_timeout/2; passtimeout: 0to disable the timeout entirely.In Elixir, a
Playwright.AbortSignal(Playwright.AbortController.signal/1).:strict(boolean/0) - Since Playwright 1.14. When true, the call requires selector to resolve to a single element. If given selector resolves to more than one element, the call fails.:timeout(number/0|:infinity) - Maximum time in milliseconds. Defaults to30000(30 seconds). Pass0to disable timeout. The default value can be changed by using thePlaywright.BrowserContext.set_default_timeout/2orPlaywright.Page.set_default_timeout/2methods.In Elixir,
:infinityis the same as0: no timeout.:trial(boolean/0) - Since Playwright 1.11. When set, this method only performs the actionability checks and skips the action. Defaults tofalse. Useful to wait until the element is ready for the action without performing it.
@spec check!(t(), String.t(), check_options()) :: :ok
Like check/3, but returns the value and raises on error.
@spec clear_console_messages(t()) :: :ok | {:error, Playwright.error()}
Clears all stored console messages from this page. Subsequent calls to Playwright.Page.console_messages/2 will only return messages logged after the clear.
Since Playwright 1.59.
@spec clear_console_messages!(t()) :: :ok
Like clear_console_messages/1, but returns the value and raises on error.
@spec clear_page_errors(t()) :: :ok | {:error, Playwright.error()}
Clears all stored page errors from this page. Subsequent calls to Playwright.Page.page_errors/2 will only return errors thrown after the clear.
Since Playwright 1.59.
@spec clear_page_errors!(t()) :: :ok
Like clear_page_errors/1, but returns the value and raises on error.
@spec click(t(), String.t(), click_options()) :: :ok | {:error, Playwright.error()}
This method clicks an element matching selector by performing the following steps:
- Find an element matching
selector. If there is none, wait until a matching element is attached to the DOM. - Wait for actionability checks on the matched element, unless
:forceoption 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/1to click in the center of the element, or the specified:position. - Wait for initiated navigations to either succeed or fail, unless
:no_wait_afteroption is set.
When all steps combined have not finished during the specified :timeout, this method fails with a
TimeoutError. Passing zero timeout disables this.
Discouraged
Use locator-based Playwright.Locator.click/2 instead. Read more about locators.
Since Playwright 1.8.
Arguments
selector- A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.
Options
:button(:left|:right|:middle) - Defaults to:left.:click_count(integer/0) - defaults to 1. SeeUIEvent.detail.:delay(number/0) - Time to wait betweenmousedownandmouseupin milliseconds. Defaults to 0.:force(boolean/0) - Whether to bypass the actionability checks. Defaults tofalse.:modifiers(list of:alt|:control|:control_or_meta|: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. "ControlOrMeta" resolves to "Control" on Windows and Linux and to "Meta" on macOS.:no_wait_after(boolean/0) - 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. Defaults tofalse.:position(map/0) - A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of the element.:x:y
:scroll(:auto|:none) - Since Playwright 1.62. Controls whether Playwright scrolls the element into view before performing the action. Defaults to:auto, which scrolls the element into view when necessary, including scrolling nested scrollable containers. When set to:none, Playwright does not scroll the element and the action fails if the element is not already in the viewport. This is useful to assert that an element is reachable by the user without additional scrolling.:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. Allows to cancel the operation using anAbortSignal. If the signal is aborted, the operation will be aborted and fail. Note that providing a signal does not disable the default timeout, which can be changed usingPlaywright.BrowserContext.set_default_timeout/2orPlaywright.Page.set_default_timeout/2; passtimeout: 0to disable the timeout entirely.In Elixir, a
Playwright.AbortSignal(Playwright.AbortController.signal/1).:strict(boolean/0) - Since Playwright 1.14. When true, the call requires selector to resolve to a single element. If given selector resolves to more than one element, the call fails.:timeout(number/0|:infinity) - Maximum time in milliseconds. Defaults to30000(30 seconds). Pass0to disable timeout. The default value can be changed by using thePlaywright.BrowserContext.set_default_timeout/2orPlaywright.Page.set_default_timeout/2methods.In Elixir,
:infinityis the same as0: no timeout.:trial(boolean/0) - Since Playwright 1.11. When set, this method only performs the actionability checks and skips the action. Defaults tofalse. Useful to wait until the element is ready for the action without performing it. Note that keyboard:modifierswill be pressed regardless of:trialto allow testing elements which are only visible when those keys are pressed.
@spec click!(t(), String.t(), click_options()) :: :ok
Like click/3, but returns the value and raises on error.
@spec clock(t()) :: Playwright.Clock.t()
Playwright has ability to mock clock and passage of time.
Since Playwright 1.45.
@spec close(t(), close_options()) :: :ok | {:error, Playwright.error()}
If :run_before_unload is false, does not run any unload handlers and waits for the page to be closed. If
:run_before_unload is true the method will run unload handlers, but will not wait for the page to close.
By default, Playwright.Page.close/2 does not run beforeunload handlers.
Note
if :run_before_unload is passed as true, a beforeunload dialog might be summoned and should be handled
manually via Page.on(:dialog) event.
Since Playwright 1.8.
Options
:reason(String.t/0) - Since Playwright 1.40. The reason to be reported to the operations interrupted by the page closure.:run_before_unload(boolean/0) - Defaults tofalse. Whether to run the before unload page handlers.
@spec close!(t(), close_options()) :: :ok
Like close/2, but returns the value and raises on error.
@spec console_messages(t(), console_messages_options()) :: {:ok, [Playwright.ConsoleMessage.t()]} | {:error, Playwright.error()}
Returns up to (currently) 200 last console messages from this page. See Page.on(:console) for more details.
Since Playwright 1.56.
Options
:filter(:all|:since_navigation) - Since Playwright 1.59. Controls which messages are returned:
@spec console_messages!(t(), console_messages_options()) :: [ Playwright.ConsoleMessage.t() ]
Like console_messages/2, but returns the value and raises on error.
@spec content(t(), content_options()) :: {:ok, String.t()} | {:error, Playwright.error()}
Gets the full HTML contents of the page, including the doctype.
Since Playwright 1.8.
Options
:include_shadow(boolean/0) - Since Playwright 1.64. When true, contents of open shadow roots are included as declarative shadow DOM, i.e.<template shadowrootmode="open">elements nested inside their host elements. Closed shadow roots are never included. Defaults tofalse.
@spec content!(t(), content_options()) :: String.t()
Like content/2, but returns the value and raises on error.
@spec context(t()) :: Playwright.BrowserContext.t()
Get the browser context that the page belongs to.
Since Playwright 1.8.
@spec coverage(t()) :: Playwright.Coverage.t()
Note
Only available for Chromium atm.
Browser-specific Coverage implementation. See Coverage for more details.
Since Playwright 1.8.
@spec dblclick(t(), String.t(), dblclick_options()) :: :ok | {:error, Playwright.error()}
This method double clicks an element matching selector by performing the following steps:
- Find an element matching
selector. If there is none, wait until a matching element is attached to the DOM. - Wait for actionability checks on the matched element, unless
:forceoption 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/1to double click in the center of the element, or the specified:position.
When all steps combined have not finished during the specified :timeout, this method fails with a
TimeoutError. Passing zero timeout disables this.
Note
Playwright.Page.dblclick/3 dispatches two click events and a single dblclick event.
Discouraged
Use locator-based Playwright.Locator.dblclick/2 instead. Read more about locators.
Since Playwright 1.8.
Arguments
selector- A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.
Options
:button(:left|:right|:middle) - Defaults to:left.:delay(number/0) - Time to wait betweenmousedownandmouseupin milliseconds. Defaults to 0.:force(boolean/0) - Whether to bypass the actionability checks. Defaults tofalse.:modifiers(list of:alt|:control|:control_or_meta|: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. "ControlOrMeta" resolves to "Control" on Windows and Linux and to "Meta" on macOS.:no_wait_after(boolean/0) - This option has no effect.:position(map/0) - A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of the element.:x:y
:scroll(:auto|:none) - Since Playwright 1.62. Controls whether Playwright scrolls the element into view before performing the action. Defaults to:auto, which scrolls the element into view when necessary, including scrolling nested scrollable containers. When set to:none, Playwright does not scroll the element and the action fails if the element is not already in the viewport. This is useful to assert that an element is reachable by the user without additional scrolling.:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. Allows to cancel the operation using anAbortSignal. If the signal is aborted, the operation will be aborted and fail. Note that providing a signal does not disable the default timeout, which can be changed usingPlaywright.BrowserContext.set_default_timeout/2orPlaywright.Page.set_default_timeout/2; passtimeout: 0to disable the timeout entirely.In Elixir, a
Playwright.AbortSignal(Playwright.AbortController.signal/1).:strict(boolean/0) - Since Playwright 1.14. When true, the call requires selector to resolve to a single element. If given selector resolves to more than one element, the call fails.:timeout(number/0|:infinity) - Maximum time in milliseconds. Defaults to30000(30 seconds). Pass0to disable timeout. The default value can be changed by using thePlaywright.BrowserContext.set_default_timeout/2orPlaywright.Page.set_default_timeout/2methods.In Elixir,
:infinityis the same as0: no timeout.:trial(boolean/0) - Since Playwright 1.11. When set, this method only performs the actionability checks and skips the action. Defaults tofalse. Useful to wait until the element is ready for the action without performing it. Note that keyboard:modifierswill be pressed regardless of:trialto allow testing elements which are only visible when those keys are pressed.
@spec dblclick!(t(), String.t(), dblclick_options()) :: :ok
Like dblclick/3, but returns the value and raises on error.
@spec dispatch_event( t(), String.t(), String.t(), term() | nil, dispatch_event_options() ) :: :ok | {:error, Playwright.error()}
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
Page.dispatch_event!(page, "button#submit", "click")Under the hood, it creates an instance of an event based on the given type, initializes it with
event_init properties and dispatches it on the element. Events are composed, cancelable and bubble by
default.
Since event_init is event-specific, please refer to the events documentation for the lists of initial
properties:
- DeviceMotionEvent
- DeviceOrientationEvent
- DragEvent
- Event
- FocusEvent
- KeyboardEvent
- MouseEvent
- PointerEvent
- TouchEvent
- WheelEvent
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
data_transfer = Page.evaluate_handle!(page, "() => new DataTransfer()")
Page.dispatch_event!(page, "#source", "dragstart", %{dataTransfer: data_transfer})Discouraged
Use locator-based Playwright.Locator.dispatch_event/4 instead. Read more about locators.
Since Playwright 1.8.
Arguments
selector- A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.type- DOM event type:"click","dragstart", etc.event_init- Optional event-specific initialization properties.
Options
:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. Allows to cancel the operation using anAbortSignal. If the signal is aborted, the operation will be aborted and fail. Note that providing a signal does not disable the default timeout, which can be changed usingPlaywright.BrowserContext.set_default_timeout/2orPlaywright.Page.set_default_timeout/2; passtimeout: 0to disable the timeout entirely.In Elixir, a
Playwright.AbortSignal(Playwright.AbortController.signal/1).:strict(boolean/0) - Since Playwright 1.14. When true, the call requires selector to resolve to a single element. If given selector resolves to more than one element, the call fails.:timeout(number/0|:infinity) - Maximum time in milliseconds. Defaults to30000(30 seconds). Pass0to disable timeout. The default value can be changed by using thePlaywright.BrowserContext.set_default_timeout/2orPlaywright.Page.set_default_timeout/2methods.In Elixir,
:infinityis the same as0: no timeout.
@spec dispatch_event!( t(), String.t(), String.t(), term() | nil, dispatch_event_options() ) :: :ok
Like dispatch_event/5, but returns the value and raises on error.
@spec drag_and_drop(t(), String.t(), String.t(), drag_and_drop_options()) :: :ok | {:error, Playwright.error()}
This method drags the source element to the target element.
It will first move to the source element, perform a mousedown,
then move to the target element and perform a mouseup.
Usage
Page.drag_and_drop!(page, "#source", "#target")
# or specify exact positions relative to the top-left corners of the elements:
Page.drag_and_drop!(page, "#source", "#target",
source_position: %{x: 34, y: 7},
target_position: %{x: 10, y: 20}
)Since Playwright 1.13.
Arguments
source- A selector to search for an element to drag. If there are multiple elements satisfying the selector, the first will be used.target- A selector to search for an element to drop onto. If there are multiple elements satisfying the selector, the first will be used.
Options
:force(boolean/0) - Whether to bypass the actionability checks. Defaults tofalse.:no_wait_after(boolean/0) - This option has no effect.:scroll(:auto|:none) - Since Playwright 1.62. Controls whether Playwright scrolls the element into view before performing the action. Defaults to:auto, which scrolls the element into view when necessary, including scrolling nested scrollable containers. When set to:none, Playwright does not scroll the element and the action fails if the element is not already in the viewport. This is useful to assert that an element is reachable by the user without additional scrolling.:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. Allows to cancel the operation using anAbortSignal. If the signal is aborted, the operation will be aborted and fail. Note that providing a signal does not disable the default timeout, which can be changed usingPlaywright.BrowserContext.set_default_timeout/2orPlaywright.Page.set_default_timeout/2; passtimeout: 0to disable the timeout entirely.In Elixir, a
Playwright.AbortSignal(Playwright.AbortController.signal/1).:source_position(map/0) - Since Playwright 1.14. Clicks on the source element at this point relative to the top-left corner of the element's padding box. If not specified, some visible point of the element is used.:x:y
:steps(integer/0) - Since Playwright 1.57. Defaults to 1. Sendsninterpolatedmousemoveevents to represent travel between themousedownandmouseupof the drag. When set to 1, emits a singlemousemoveevent at the destination location.:strict(boolean/0) - Since Playwright 1.14. When true, the call requires selector to resolve to a single element. If given selector resolves to more than one element, the call fails.:target_position(map/0) - Since Playwright 1.14. Drops on the target element at this point relative to the top-left corner of the element's padding box. If not specified, some visible point of the element is used.:x:y
:timeout(number/0|:infinity) - Maximum time in milliseconds. Defaults to30000(30 seconds). Pass0to disable timeout. The default value can be changed by using thePlaywright.BrowserContext.set_default_timeout/2orPlaywright.Page.set_default_timeout/2methods.In Elixir,
:infinityis the same as0: no timeout.:trial(boolean/0) - When set, this method only performs the actionability checks and skips the action. Defaults tofalse. Useful to wait until the element is ready for the action without performing it.
@spec drag_and_drop!(t(), String.t(), String.t(), drag_and_drop_options()) :: :ok
Like drag_and_drop/4, but returns the value and raises on error.
@spec emulate_media(t(), emulate_media_options()) :: :ok | {:error, Playwright.error()}
This method changes the CSS media type through the :media option, and/or the 'prefers-colors-scheme' media feature, using the :color_scheme option.
Usage
Page.evaluate!(page, "() => matchMedia('screen').matches")
# => true
Page.evaluate!(page, "() => matchMedia('print').matches")
# => false
Page.emulate_media!(page, media: :print)
Page.evaluate!(page, "() => matchMedia('screen').matches")
# => false
Page.evaluate!(page, "() => matchMedia('print').matches")
# => true
# `:null` (JS `null`) removes the emulation, leaving `:media` out keeps it.
Page.emulate_media!(page, media: :null)
Page.evaluate!(page, "() => matchMedia('screen').matches")
# => true
Page.evaluate!(page, "() => matchMedia('print').matches")
# => falsePage.emulate_media!(page, color_scheme: :dark)
Page.evaluate!(page, "() => matchMedia('(prefers-color-scheme: dark)').matches")
# => true
Page.evaluate!(page, "() => matchMedia('(prefers-color-scheme: light)').matches")
# => falseSince Playwright 1.8.
Options
:color_scheme(:null|:light|:dark|:no_preference) - Since Playwright 1.9. Emulates prefers-colors-scheme media feature, supported values are:lightand:dark. Passing:nulldisables color scheme emulation.:no_preferenceis deprecated.:contrast(:null|:no_preference|:more) - Since Playwright 1.51. Emulates'prefers-contrast'media feature, supported values are:no_preference,:more. Passing:nulldisables contrast emulation.:forced_colors(:null|:active|:none) - Since Playwright 1.15. Emulates'forced-colors'media feature, supported values are:activeand:none. Passing:nulldisables forced colors emulation.:media(:null|:screen|:print) - Since Playwright 1.9. Changes the CSS media type of the page. The only allowed values are:screen,:printand:null. Passing:nulldisables CSS media emulation.:reduced_motion(:null|:reduce|:no_preference) - Since Playwright 1.12. Emulates'prefers-reduced-motion'media feature, supported values are:reduce,:no_preference. Passing:nulldisables reduced motion emulation.
@spec emulate_media!(t(), emulate_media_options()) :: :ok
Like emulate_media/2, but returns the value and raises on error.
@spec eval_on_selector(t(), String.t(), String.t(), term() | nil) :: {:ok, term()} | {:error, Playwright.error()}
The method finds an element matching the specified selector within the page and passes it as a first argument to
expression. If no elements match the selector, the method fails. Returns the value of
expression.
If expression returns a Promise, then Playwright.Page.eval_on_selector/4 would wait for the promise to resolve and
return its value.
Usage
search_value = Page.eval_on_selector!(page, "#search", "el => el.value")
preload_href = Page.eval_on_selector!(page, "link[rel=preload]", "el => el.href")
html = Page.eval_on_selector!(page, ".main-container", "(e, suffix) => e.outerHTML + suffix", "hello")Discouraged
This method does not wait for the element to pass actionability
checks and therefore can lead to the flaky tests. Use Playwright.Locator.evaluate/4,
other Locator helper methods or web-first assertions instead.
Since Playwright 1.9.
Arguments
selector- A selector to query for.expression- Function to be evaluated in the page context.arg- Optional argument to pass toexpression.
Like eval_on_selector/4, but returns the value and raises on error.
@spec eval_on_selector_all(t(), String.t(), String.t(), term() | nil) :: {:ok, term()} | {:error, Playwright.error()}
The method finds all elements matching the specified selector within the page and passes an array of matched elements as
a first argument to expression. Returns the result of expression invocation.
If expression returns a Promise, then Playwright.Page.eval_on_selector_all/4 would wait for the promise to resolve and
return its value.
Usage
div_counts = Page.eval_on_selector_all!(page, "div", "(divs, min) => divs.length >= min", 10)Discouraged
In most cases, Playwright.Locator.evaluate_all/3,
other Locator helper methods and web-first assertions do a better job.
Since Playwright 1.9.
Arguments
selector- A selector to query for.expression- Function to be evaluated in the page context.arg- Optional argument to pass toexpression.
Like eval_on_selector_all/4, but returns the value and raises on error.
@spec evaluate(t(), String.t(), term() | nil, evaluate_options()) :: {:ok, term()} | {:error, Playwright.error()}
Returns the value of the expression invocation.
If the function passed to the Playwright.Page.evaluate/4 returns a Promise, then Playwright.Page.evaluate/4 would wait
for the promise to resolve and return its value.
If the function passed to the Playwright.Page.evaluate/4 returns a non-Serializable value, then
Playwright.Page.evaluate/4 returns nil. Playwright also supports transferring some
additional values that are not serializable by JSON: -0, NaN, Infinity, -Infinity.
Usage
Passing argument to expression:
result = Page.evaluate!(page, "([x, y]) => Promise.resolve(x * y)", [7, 8])
# prints "56"
IO.puts(result)A string can also be passed in instead of a function:
# prints "3"
IO.puts(Page.evaluate!(page, "1 + 2"))
x = 10
# prints "11"
IO.puts(Page.evaluate!(page, "1 + #{x}"))ElementHandle instances can be passed as an argument to the Playwright.Page.evaluate/4:
body_handle = Page.evaluate_handle!(page, "document.body")
html = Page.evaluate!(page, "([body, suffix]) => body.innerHTML + suffix", [body_handle, "hello"])
JSHandle.dispose!(body_handle)Since Playwright 1.8.
Arguments
expression- Function to be evaluated in the page context.arg- Optional argument to pass toexpression.
Options
:expose_functions(boolean/0) - Since Playwright 1.62. When set totrue, functions passed insideargare exposed in the page and can be called from the page function. Calling one returns aPromiseof its result. Under the hood, each function is exposed viaPlaywright.Page.expose_function/3, so it is technically accessible from all frames of the page. Exposed functions are cleared upon the top-level navigation. Defaults tofalse, in which case functions are not serializable and passing one fails.
@spec evaluate!(t(), String.t(), term() | nil, evaluate_options()) :: term()
Like evaluate/4, but returns the value and raises on error.
@spec evaluate_handle(t(), String.t(), term() | nil, evaluate_handle_options()) :: {:ok, Playwright.JSHandle.t()} | {:error, Playwright.error()}
Returns the value of the expression invocation as a JSHandle.
The only difference between Playwright.Page.evaluate/4 and Playwright.Page.evaluate_handle/4 is that Playwright.Page.evaluate_handle/4 returns JSHandle.
If the function passed to the Playwright.Page.evaluate_handle/4 returns a Promise, then Playwright.Page.evaluate_handle/4 would wait for the
promise to resolve and return its value.
Usage
# Handle for the window object.
a_window_handle = Page.evaluate_handle!(page, "() => Promise.resolve(window)")A string can also be passed in instead of a function:
# Handle for the "document"
a_handle = Page.evaluate_handle!(page, "document")JSHandle instances can be passed as an argument to the Playwright.Page.evaluate_handle/4:
a_handle = Page.evaluate_handle!(page, "() => document.body")
result_handle = Page.evaluate_handle!(page, "body => body.innerHTML", a_handle)
IO.puts(JSHandle.json_value!(result_handle))
JSHandle.dispose!(result_handle)Since Playwright 1.8.
Arguments
expression- Function to be evaluated in the page context.arg- Optional argument to pass toexpression.
Options
:expose_functions(boolean/0) - Since Playwright 1.62. When set totrue, functions passed insideargare exposed in the page and can be called from the page function. Calling one returns aPromiseof its result. Under the hood, each function is exposed viaPlaywright.Page.expose_function/3, so it is technically accessible from all frames of the page. Exposed functions are cleared upon the top-level navigation. Defaults tofalse, in which case functions are not serializable and passing one fails.
@spec evaluate_handle!(t(), String.t(), term() | nil, evaluate_handle_options()) :: Playwright.JSHandle.t()
Like evaluate_handle/4, but returns the value and raises on error.
@spec expect_console_message( t(), (-> term()), expect_console_message_options() | fun() ) :: {:ok, Playwright.ConsoleMessage.t()} | {:error, Playwright.error()}
Performs action and waits for a ConsoleMessage to be logged by in the page. If predicate is provided, it passes
ConsoleMessage value into the :predicate function and waits for predicate(message) to return a truthy value.
Will fail if the page is closed before the Page.on(:console) event is fired.
Since Playwright 1.9.
Arguments
action- A function that performs the action triggering the wait. It runs once the wait is set up; its result is ignored and what it raises propagates.
Options
A function in place of the options is the :predicate option.
:predicate((Playwright.ConsoleMessage.t() -> boolean())) - Receives theConsoleMessageobject and returns a truthy value when the waiting should resolve.:timeout(number/0|:infinity) - Maximum time to wait for in milliseconds. Defaults to30000(30 seconds). Pass0to disable timeout. The default value can be changed by using thePlaywright.BrowserContext.set_default_timeout/2.In Elixir,
:infinityis the same as0: no timeout.:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. Allows to cancel the waiting using anAbortSignal. If the signal is aborted, the waiting will be aborted and the operation will fail. Note that providing a signal does not disable the default timeout, which can be changed usingPlaywright.BrowserContext.set_default_timeout/2; passtimeout: 0to disable the timeout entirely.In Elixir, a
Playwright.AbortSignal(Playwright.AbortController.signal/1).In Elixir, a
Playwright.AbortSignal(Playwright.AbortController.signal/1).
@spec expect_console_message!( t(), (-> term()), expect_console_message_options() | fun() ) :: Playwright.ConsoleMessage.t()
Like expect_console_message/3, but returns the value and raises on error.
@spec expect_download(t(), (-> term()), expect_download_options() | fun()) :: {:ok, Playwright.Download.t()} | {:error, Playwright.error()}
Performs action and waits for a new Download. If predicate is provided, it passes
Download value into the :predicate function and waits for predicate(download) to return a truthy value.
Will fail if the page is closed before the download event is fired.
Since Playwright 1.9.
Arguments
action- A function that performs the action triggering the wait. It runs once the wait is set up; its result is ignored and what it raises propagates.
Options
A function in place of the options is the :predicate option.
:predicate((Playwright.Download.t() -> boolean())) - Receives theDownloadobject and returns a truthy value when the waiting should resolve.:timeout(number/0|:infinity) - Maximum time to wait for in milliseconds. Defaults to30000(30 seconds). Pass0to disable timeout. The default value can be changed by using thePlaywright.BrowserContext.set_default_timeout/2.In Elixir,
:infinityis the same as0: no timeout.:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. Allows to cancel the waiting using anAbortSignal. If the signal is aborted, the waiting will be aborted and the operation will fail. Note that providing a signal does not disable the default timeout, which can be changed usingPlaywright.BrowserContext.set_default_timeout/2; passtimeout: 0to disable the timeout entirely.In Elixir, a
Playwright.AbortSignal(Playwright.AbortController.signal/1).In Elixir, a
Playwright.AbortSignal(Playwright.AbortController.signal/1).
@spec expect_download!(t(), (-> term()), expect_download_options() | fun()) :: Playwright.Download.t()
Like expect_download/3, but returns the value and raises on error.
@spec expect_event( t(), event() | String.t(), (-> term()), expect_event_options() | fun() ) :: {:ok, term()} | {:error, Playwright.error()}
Waits for event to fire and passes its value into the predicate function. Returns when the predicate returns truthy value. Will fail if the page is closed before the event is fired. Returns the event data value.
Usage
# Start waiting for download before clicking: a promise, awaited after.
download_promise = Page.wait_for_event(page, :download)
Page.get_by_text(page, "Download file") |> Locator.click!()
download = Promise.await!(download_promise)Since Playwright 1.8.
Arguments
event- Event name, same one typically passed intoPlaywright.Page.on/3.action- A function that performs the action triggering the wait. It runs once the wait is set up; its result is ignored and what it raises propagates.
Options
A function in place of the options is the :predicate option.
:predicate(fun/0) - Receives the event data and returns a truthy value when the waiting should resolve.:timeout(number/0|:infinity) - Maximum time to wait for in milliseconds. Defaults to30000(30 seconds). Pass0to disable timeout. The default value can be changed withPlaywright.Page.set_default_timeout/2orPlaywright.BrowserContext.set_default_timeout/2.In Elixir,
:infinityis the same as0: no timeout.:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. Allows to cancel the waiting using anAbortSignal. If the signal is aborted, the waiting will be aborted and the operation will fail. Note that providing a signal does not disable the default timeout, which can be changed usingPlaywright.BrowserContext.set_default_timeout/2; passtimeout: 0to disable the timeout entirely.In Elixir, a
Playwright.AbortSignal(Playwright.AbortController.signal/1).In Elixir, a
Playwright.AbortSignal(Playwright.AbortController.signal/1).
@spec expect_event!( t(), event() | String.t(), (-> term()), expect_event_options() | fun() ) :: term()
Like expect_event/4, but returns the value and raises on error.
@spec expect_file_chooser(t(), (-> term()), expect_file_chooser_options() | fun()) :: {:ok, Playwright.FileChooser.t()} | {:error, Playwright.error()}
Performs action and waits for a new FileChooser to be created. If predicate is provided, it passes
FileChooser value into the :predicate function and waits for predicate(fileChooser) to return a truthy value.
Will fail if the page is closed before the file chooser is opened.
Since Playwright 1.9.
Arguments
action- A function that performs the action triggering the wait. It runs once the wait is set up; its result is ignored and what it raises propagates.
Options
A function in place of the options is the :predicate option.
:predicate((Playwright.FileChooser.t() -> boolean())) - Receives theFileChooserobject and returns a truthy value when the waiting should resolve.:timeout(number/0|:infinity) - Maximum time to wait for in milliseconds. Defaults to30000(30 seconds). Pass0to disable timeout. The default value can be changed by using thePlaywright.BrowserContext.set_default_timeout/2.In Elixir,
:infinityis the same as0: no timeout.:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. Allows to cancel the waiting using anAbortSignal. If the signal is aborted, the waiting will be aborted and the operation will fail. Note that providing a signal does not disable the default timeout, which can be changed usingPlaywright.BrowserContext.set_default_timeout/2; passtimeout: 0to disable the timeout entirely.In Elixir, a
Playwright.AbortSignal(Playwright.AbortController.signal/1).In Elixir, a
Playwright.AbortSignal(Playwright.AbortController.signal/1).
@spec expect_file_chooser!(t(), (-> term()), expect_file_chooser_options() | fun()) :: Playwright.FileChooser.t()
Like expect_file_chooser/3, but returns the value and raises on error.
@spec expect_popup(t(), (-> term()), expect_popup_options() | fun()) :: {:ok, t()} | {:error, Playwright.error()}
Performs action and waits for a popup Page. If predicate is provided, it passes
Popup value into the :predicate function and waits for predicate(page) to return a truthy value.
Will fail if the page is closed before the popup event is fired.
Since Playwright 1.9.
Arguments
action- A function that performs the action triggering the wait. It runs once the wait is set up; its result is ignored and what it raises propagates.
Options
A function in place of the options is the :predicate option.
:predicate((Playwright.Page.t() -> boolean())) - Receives thePageobject and returns a truthy value when the waiting should resolve.:timeout(number/0|:infinity) - Maximum time to wait for in milliseconds. Defaults to30000(30 seconds). Pass0to disable timeout. The default value can be changed by using thePlaywright.BrowserContext.set_default_timeout/2.In Elixir,
:infinityis the same as0: no timeout.:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. Allows to cancel the waiting using anAbortSignal. If the signal is aborted, the waiting will be aborted and the operation will fail. Note that providing a signal does not disable the default timeout, which can be changed usingPlaywright.BrowserContext.set_default_timeout/2; passtimeout: 0to disable the timeout entirely.In Elixir, a
Playwright.AbortSignal(Playwright.AbortController.signal/1).In Elixir, a
Playwright.AbortSignal(Playwright.AbortController.signal/1).
@spec expect_popup!(t(), (-> term()), expect_popup_options() | fun()) :: t()
Like expect_popup/3, but returns the value and raises on error.
@spec expect_request( t(), String.t() | Regex.t() | Playwright.RegExp.t() | (Playwright.Request.t() -> boolean()), (-> term()), expect_request_options() ) :: {:ok, Playwright.Request.t()} | {:error, Playwright.error()}
Waits for the matching request and returns it. See waiting for event for more details about events.
Usage
# Start waiting for request before clicking: a promise, awaited after.
request_promise = Page.wait_for_request(page, "https://example.com/resource")
Page.get_by_text(page, "trigger request") |> Locator.click!()
first_request = Promise.await!(request_promise)
# Alternative way with a predicate.
request_promise =
Page.wait_for_request(page, fn request ->
Request.url(request) == "https://example.com/" and Request.method(request) == "GET"
end)
Page.get_by_text(page, "trigger request") |> Locator.click!()
second_request = Promise.await!(request_promise)Since Playwright 1.8.
Arguments
url_or_predicate- Request URL string, regex or predicate receivingRequestobject. When a:base_urlvia the context options was provided and the passed URL is a path, it gets merged via thenew URL()constructor.action- A function that performs the action triggering the wait. It runs once the wait is set up; its result is ignored and what it raises propagates.
Options
:timeout(number/0|:infinity) - Maximum wait time in milliseconds, defaults to 30 seconds, pass0to disable the timeout. The default value can be changed by using thePlaywright.Page.set_default_timeout/2method.In Elixir,
:infinityis the same as0: no timeout.:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. Allows to cancel the waiting using anAbortSignal. If the signal is aborted, the waiting will be aborted and the operation will fail. Note that providing a signal does not disable the default timeout, which can be changed usingPlaywright.BrowserContext.set_default_timeout/2; passtimeout: 0to disable the timeout entirely.In Elixir, a
Playwright.AbortSignal(Playwright.AbortController.signal/1).In Elixir, a
Playwright.AbortSignal(Playwright.AbortController.signal/1).
@spec expect_request!( t(), String.t() | Regex.t() | Playwright.RegExp.t() | (Playwright.Request.t() -> boolean()), (-> term()), expect_request_options() ) :: Playwright.Request.t()
Like expect_request/4, but returns the value and raises on error.
@spec expect_request_finished( t(), (-> term()), expect_request_finished_options() | fun() ) :: {:ok, Playwright.Request.t()} | {:error, Playwright.error()}
Performs action and waits for a Request to finish loading. If predicate is provided, it passes
Request value into the :predicate function and waits for predicate(request) to return a truthy value.
Will fail if the page is closed before the Page.on(:request_finished) event is fired.
Since Playwright 1.12.
Arguments
action- A function that performs the action triggering the wait. It runs once the wait is set up; its result is ignored and what it raises propagates.
Options
A function in place of the options is the :predicate option.
:predicate((Playwright.Request.t() -> boolean())) - Receives theRequestobject and returns a truthy value when the waiting should resolve.:timeout(number/0|:infinity) - Maximum time to wait for in milliseconds. Defaults to30000(30 seconds). Pass0to disable timeout. The default value can be changed by using thePlaywright.BrowserContext.set_default_timeout/2.In Elixir,
:infinityis the same as0: no timeout.:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. Allows to cancel the waiting using anAbortSignal. If the signal is aborted, the waiting will be aborted and the operation will fail. Note that providing a signal does not disable the default timeout, which can be changed usingPlaywright.BrowserContext.set_default_timeout/2; passtimeout: 0to disable the timeout entirely.In Elixir, a
Playwright.AbortSignal(Playwright.AbortController.signal/1).In Elixir, a
Playwright.AbortSignal(Playwright.AbortController.signal/1).
@spec expect_request_finished!( t(), (-> term()), expect_request_finished_options() | fun() ) :: Playwright.Request.t()
Like expect_request_finished/3, but returns the value and raises on error.
@spec expect_response( t(), String.t() | Regex.t() | Playwright.RegExp.t() | (Playwright.Response.t() -> boolean()), (-> term()), expect_response_options() ) :: {:ok, Playwright.Response.t()} | {:error, Playwright.error()}
Returns the matched response. See waiting for event for more details about events.
Usage
# Start waiting for response before clicking: a promise, awaited after.
response_promise = Page.wait_for_response(page, "https://example.com/resource")
Page.get_by_text(page, "trigger response") |> Locator.click!()
first_response = Promise.await!(response_promise)
# Alternative way with a predicate.
response_promise =
Page.wait_for_response(page, fn response ->
Response.url(response) == "https://example.com/" and Response.status(response) == 200 and
Request.method(Response.request(response)) == "GET"
end)
Page.get_by_text(page, "trigger response") |> Locator.click!()
second_response = Promise.await!(response_promise)Since Playwright 1.8.
Arguments
url_or_predicate- Request URL string, regex or predicate receivingResponseobject. When a:base_urlvia the context options was provided and the passed URL is a path, it gets merged via thenew URL()constructor.action- A function that performs the action triggering the wait. It runs once the wait is set up; its result is ignored and what it raises propagates.
Options
:timeout(number/0|:infinity) - Maximum wait time in milliseconds, defaults to 30 seconds, pass0to disable the timeout. The default value can be changed by using thePlaywright.BrowserContext.set_default_timeout/2orPlaywright.Page.set_default_timeout/2methods.In Elixir,
:infinityis the same as0: no timeout.:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. Allows to cancel the waiting using anAbortSignal. If the signal is aborted, the waiting will be aborted and the operation will fail. Note that providing a signal does not disable the default timeout, which can be changed usingPlaywright.BrowserContext.set_default_timeout/2; passtimeout: 0to disable the timeout entirely.In Elixir, a
Playwright.AbortSignal(Playwright.AbortController.signal/1).In Elixir, a
Playwright.AbortSignal(Playwright.AbortController.signal/1).
@spec expect_response!( t(), String.t() | Regex.t() | Playwright.RegExp.t() | (Playwright.Response.t() -> boolean()), (-> term()), expect_response_options() ) :: Playwright.Response.t()
Like expect_response/4, but returns the value and raises on error.
@spec expect_websocket(t(), (-> term()), expect_websocket_options() | fun()) :: {:ok, Playwright.WebSocket.t()} | {:error, Playwright.error()}
Performs action and waits for a new WebSocket. If predicate is provided, it passes
WebSocket value into the :predicate function and waits for predicate(webSocket) to return a truthy value.
Will fail if the page is closed before the WebSocket event is fired.
Since Playwright 1.9.
Arguments
action- A function that performs the action triggering the wait. It runs once the wait is set up; its result is ignored and what it raises propagates.
Options
A function in place of the options is the :predicate option.
:predicate((Playwright.WebSocket.t() -> boolean())) - Receives theWebSocketobject and returns a truthy value when the waiting should resolve.:timeout(number/0|:infinity) - Maximum time to wait for in milliseconds. Defaults to30000(30 seconds). Pass0to disable timeout. The default value can be changed by using thePlaywright.BrowserContext.set_default_timeout/2.In Elixir,
:infinityis the same as0: no timeout.:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. Allows to cancel the waiting using anAbortSignal. If the signal is aborted, the waiting will be aborted and the operation will fail. Note that providing a signal does not disable the default timeout, which can be changed usingPlaywright.BrowserContext.set_default_timeout/2; passtimeout: 0to disable the timeout entirely.In Elixir, a
Playwright.AbortSignal(Playwright.AbortController.signal/1).In Elixir, a
Playwright.AbortSignal(Playwright.AbortController.signal/1).
@spec expect_websocket!(t(), (-> term()), expect_websocket_options() | fun()) :: Playwright.WebSocket.t()
Like expect_websocket/3, but returns the value and raises on error.
@spec expect_worker(t(), (-> term()), expect_worker_options() | fun()) :: {:ok, Playwright.Worker.t()} | {:error, Playwright.error()}
Performs action and waits for a new Worker. If predicate is provided, it passes
Worker value into the :predicate function and waits for predicate(worker) to return a truthy value.
Will fail if the page is closed before the worker event is fired.
Since Playwright 1.9.
Arguments
action- A function that performs the action triggering the wait. It runs once the wait is set up; its result is ignored and what it raises propagates.
Options
A function in place of the options is the :predicate option.
:predicate((Playwright.Worker.t() -> boolean())) - Receives theWorkerobject and returns a truthy value when the waiting should resolve.:timeout(number/0|:infinity) - Maximum time to wait for in milliseconds. Defaults to30000(30 seconds). Pass0to disable timeout. The default value can be changed by using thePlaywright.BrowserContext.set_default_timeout/2.In Elixir,
:infinityis the same as0: no timeout.:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. Allows to cancel the waiting using anAbortSignal. If the signal is aborted, the waiting will be aborted and the operation will fail. Note that providing a signal does not disable the default timeout, which can be changed usingPlaywright.BrowserContext.set_default_timeout/2; passtimeout: 0to disable the timeout entirely.In Elixir, a
Playwright.AbortSignal(Playwright.AbortController.signal/1).In Elixir, a
Playwright.AbortSignal(Playwright.AbortController.signal/1).
@spec expect_worker!(t(), (-> term()), expect_worker_options() | fun()) :: Playwright.Worker.t()
Like expect_worker/3, but returns the value and raises on error.
@spec expose_binding(t(), String.t(), fun()) :: {:ok, Playwright.Disposable.t()} | {:error, Playwright.error()}
The method adds a function called name on the window object of every frame in this page. When called, the
function executes callback and returns a Promise which resolves to the return value of callback.
If callback returns a Playwright.Promise, it is awaited.
The first argument of the callback function contains information about the caller: { browserContext: BrowserContext, page: Page, frame: Frame }.
See Playwright.BrowserContext.expose_binding/3 for the context-wide version.
Note
Functions installed via Playwright.Page.expose_binding/3 survive navigations.
Usage
An example of exposing page URL to all frames in a page:
# Or Playwright.chromium/1 or Playwright.firefox/1.
browser = Playwright.webkit(playwright) |> BrowserType.launch!(headless: false)
context = Browser.new_context!(browser)
page = BrowserContext.new_page!(context)
Page.expose_binding!(page, "pageURL", fn %{page: page} -> Page.url(page) end)
Page.set_content!(page, """
<script>
async function onClick() {
document.querySelector('div').textContent = await window.pageURL();
}
</script>
<button onclick="onClick()">Click me</button>
<div></div>
""")
Page.click!(page, "button")Since Playwright 1.8.
Arguments
name- Name of the function on the window object.callback- Callback function that will be called in the Playwright's context.
@spec expose_binding!(t(), String.t(), fun()) :: Playwright.Disposable.t()
Like expose_binding/3, but returns the value and raises on error.
@spec expose_function(t(), String.t(), fun()) :: {:ok, Playwright.Disposable.t()} | {:error, Playwright.error()}
The method adds a function called name on the window object of every frame in the page. When called, the
function executes callback and returns a Promise which resolves to the return value of callback.
If callback returns a Playwright.Promise, it is awaited.
See Playwright.BrowserContext.expose_function/3 for context-wide exposed function.
Note
Functions installed via Playwright.Page.expose_function/3 survive navigations.
Usage
An example of adding a sha256 function to the page:
# Or Playwright.chromium/1 or Playwright.firefox/1.
browser = Playwright.webkit(playwright) |> BrowserType.launch!(headless: false)
page = Browser.new_page!(browser)
Page.expose_function!(page, "sha256", fn text ->
:crypto.hash(:sha256, text) |> Base.encode16(case: :lower)
end)
Page.set_content!(page, """
<script>
async function onClick() {
document.querySelector('div').textContent = await window.sha256('PLAYWRIGHT');
}
</script>
<button onclick="onClick()">Click me</button>
<div></div>
""")
Page.click!(page, "button")Since Playwright 1.8.
Arguments
name- Name of the function on the window objectcallback- Callback function which will be called in Playwright's context.
@spec expose_function!(t(), String.t(), fun()) :: Playwright.Disposable.t()
Like expose_function/3, but returns the value and raises on error.
@spec fill(t(), String.t(), String.t(), fill_options()) :: :ok | {:error, Playwright.error()}
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 fails. 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 Playwright.Locator.press_sequentially/3.
Discouraged
Use locator-based Playwright.Locator.fill/3 instead. Read more about locators.
Since Playwright 1.8.
Arguments
selector- A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.value- Value to fill for the<input>,<textarea>or[contenteditable]element.
Options
:force(boolean/0) - Since Playwright 1.13. Whether to bypass the actionability checks. Defaults tofalse.:no_wait_after(boolean/0) - This option has no effect.:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. Allows to cancel the operation using anAbortSignal. If the signal is aborted, the operation will be aborted and fail. Note that providing a signal does not disable the default timeout, which can be changed usingPlaywright.BrowserContext.set_default_timeout/2orPlaywright.Page.set_default_timeout/2; passtimeout: 0to disable the timeout entirely.In Elixir, a
Playwright.AbortSignal(Playwright.AbortController.signal/1).:strict(boolean/0) - Since Playwright 1.14. When true, the call requires selector to resolve to a single element. If given selector resolves to more than one element, the call fails.:timeout(number/0|:infinity) - Maximum time in milliseconds. Defaults to30000(30 seconds). Pass0to disable timeout. The default value can be changed by using thePlaywright.BrowserContext.set_default_timeout/2orPlaywright.Page.set_default_timeout/2methods.In Elixir,
:infinityis the same as0: no timeout.
@spec fill!(t(), String.t(), String.t(), fill_options()) :: :ok
Like fill/4, but returns the value and raises on error.
@spec focus(t(), String.t(), focus_options()) :: :ok | {:error, Playwright.error()}
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.
Discouraged
Use locator-based Playwright.Locator.focus/2 instead. Read more about locators.
Since Playwright 1.8.
Arguments
selector- A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.
Options
:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. Allows to cancel the operation using anAbortSignal. If the signal is aborted, the operation will be aborted and fail. Note that providing a signal does not disable the default timeout, which can be changed usingPlaywright.BrowserContext.set_default_timeout/2orPlaywright.Page.set_default_timeout/2; passtimeout: 0to disable the timeout entirely.In Elixir, a
Playwright.AbortSignal(Playwright.AbortController.signal/1).:strict(boolean/0) - Since Playwright 1.14. When true, the call requires selector to resolve to a single element. If given selector resolves to more than one element, the call fails.:timeout(number/0|:infinity) - Maximum time in milliseconds. Defaults to30000(30 seconds). Pass0to disable timeout. The default value can be changed by using thePlaywright.BrowserContext.set_default_timeout/2orPlaywright.Page.set_default_timeout/2methods.In Elixir,
:infinityis the same as0: no timeout.
@spec focus!(t(), String.t(), focus_options()) :: :ok
Like focus/3, but returns the value and raises on error.
@spec frame( t(), String.t() | %{ optional(:name) => String.t(), optional(:url) => String.t() | Regex.t() | Playwright.RegExp.t() | (URI.t() -> boolean()) } ) :: nil | Playwright.Frame.t()
Returns frame matching the specified criteria. Either name or url must be specified.
Usage
frame = Page.frame(page, "frame-name")frame = Page.frame(page, %{url: ~r/.*domain.*/})Since Playwright 1.8.
Arguments
frame_selector- Frame name or other frame lookup options.:name- Frame name specified in theiframe'snameattribute. Optional.:url- A glob pattern, regex pattern, URL pattern, or predicate receiving frame'surlas aURIobject. Optional.
@spec frame_locator(t(), String.t() | nil) :: Playwright.FrameLocator.t()
When working with iframes, you can create a frame locator that will enter the iframe and allow selecting elements in that iframe.
When called without selector, the search starts in any frame on the page - the main frame or any of
the iframes - so that you don't need to locate each iframe first. Note that the rest of the locator is resolved
inside a single frame, just like any other locator. If it matches elements inside multiple frames, the call fails.
Usage
Following snippet locates element with text "Submit" in the iframe with id my-frame,
like <iframe id="my-frame">:
locator = Page.frame_locator(page, "#my-iframe") |> FrameLocator.get_by_text("Submit")
Locator.click!(locator)Following snippet locates a button, either in the main frame or in one of the iframes:
locator = Page.frame_locator(page) |> FrameLocator.get_by_role(:button)
Locator.click!(locator)Since Playwright 1.17.
Arguments
selector- A selector that matches the frame element. When not specified, locator is matched in any frame on the page.
@spec frames(t()) :: [Playwright.Frame.t()]
An array of all frames attached to the page.
Since Playwright 1.8.
@spec get_attribute(t(), String.t(), String.t(), get_attribute_options()) :: {:ok, nil | String.t()} | {:error, Playwright.error()}
Returns element attribute value.
Discouraged
Use locator-based Playwright.Locator.get_attribute/3 instead. Read more about locators.
Since Playwright 1.8.
Arguments
selector- A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.name- Attribute name to get the value for.
Options
:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. Allows to cancel the operation using anAbortSignal. If the signal is aborted, the operation will be aborted and fail. Note that providing a signal does not disable the default timeout, which can be changed usingPlaywright.BrowserContext.set_default_timeout/2orPlaywright.Page.set_default_timeout/2; passtimeout: 0to disable the timeout entirely.In Elixir, a
Playwright.AbortSignal(Playwright.AbortController.signal/1).:strict(boolean/0) - Since Playwright 1.14. When true, the call requires selector to resolve to a single element. If given selector resolves to more than one element, the call fails.:timeout(number/0|:infinity) - Maximum time in milliseconds. Defaults to30000(30 seconds). Pass0to disable timeout. The default value can be changed by using thePlaywright.BrowserContext.set_default_timeout/2orPlaywright.Page.set_default_timeout/2methods.In Elixir,
:infinityis the same as0: no timeout.
@spec get_attribute!(t(), String.t(), String.t(), get_attribute_options()) :: nil | String.t()
Like get_attribute/4, but returns the value and raises on error.
@spec get_by_alt_text( t(), String.t() | Regex.t() | Playwright.RegExp.t(), get_by_alt_text_options() ) :: Playwright.Locator.t()
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(page, "Playwright logo") |> Locator.click!()Since Playwright 1.27.
Arguments
text- Text to locate the element for.
Options
:exact(boolean/0) - 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 get_by_label( t(), String.t() | Regex.t() | Playwright.RegExp.t(), get_by_label_options() ) :: Playwright.Locator.t()
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(page, "Username") |> Locator.fill!("john")
Page.get_by_label(page, "Password") |> Locator.fill!("secret")Since Playwright 1.27.
Arguments
text- Text to locate the element for.
Options
:exact(boolean/0) - 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 get_by_placeholder( t(), String.t() | Regex.t() | Playwright.RegExp.t(), get_by_placeholder_options() ) :: Playwright.Locator.t()
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(page, "name@example.com") |> Locator.fill!("playwright@microsoft.com")Since Playwright 1.27.
Arguments
text- Text to locate the element for.
Options
:exact(boolean/0) - 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 get_by_ref(t(), String.t()) :: Playwright.Locator.t()
Locate element by its aria ref. Refs like [ref=e2] are reported by Playwright.Page.aria_snapshot/2 when called with
the "ai" mode, and resolve against the latest snapshot taken in the element's frame.
Usage
Consider the following aria snapshot.
- button "Submit" [ref=e2]You can locate the button by its ref:
Page.get_by_ref(page, "e2") |> Locator.click!()Since Playwright 1.64.
Arguments
ref- Aria ref of the element, for examplee2orf1e3.
@spec get_by_role( t(), :alert | :alertdialog | :application | :article | :banner | :blockquote | :button | :caption | :cell | :checkbox | :code | :columnheader | :combobox | :complementary | :contentinfo | :definition | :deletion | :dialog | :directory | :document | :emphasis | :feed | :figure | :form | :generic | :grid | :gridcell | :group | :heading | :img | :insertion | :link | :list | :listbox | :listitem | :log | :main | :marquee | :math | :meter | :menu | :menubar | :menuitem | :menuitemcheckbox | :menuitemradio | :navigation | :none | :note | :option | :paragraph | :presentation | :progressbar | :radio | :radiogroup | :region | :row | :rowgroup | :rowheader | :scrollbar | :search | :searchbox | :separator | :slider | :spinbutton | :status | :strong | :subscript | :superscript | :switch | :tab | :table | :tablist | :tabpanel | :term | :textbox | :time | :timer | :toolbar | :tooltip | :tree | :treegrid | :treeitem | String.t(), get_by_role_options() ) :: Playwright.Locator.t()
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 its implicit role:
Page.get_by_role(page, :heading, name: "Sign up") |> Expect.to_be_visible!()
Page.get_by_role(page, :checkbox, name: "Subscribe") |> Locator.check!()
Page.get_by_role(page, :button, name: ~r/submit/i) |> Locator.click!()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.
Since Playwright 1.27.
Arguments
role- Required aria role.In Elixir, a role is an atom of the typespec (
:button) or a string, also one the typespec lacks ("mark"): the JS client takes any string.
Options
:checked(boolean/0) - An attribute that is usually set byaria-checkedor native<input type=checkbox>controls.Learn more about
aria-checked.:description(String.t/0|Regex.t/0|Playwright.RegExp.t/0) - Since Playwright 1.60. Option to match the accessible description. By default, matching is case-insensitive and searches for a substring, use:exactto control this behavior.Learn more about accessible description.
:disabled(boolean/0) - An attribute that is usually set byaria-disabledordisabled.Note
Unlike most other attributes,
disabledis inherited through the DOM hierarchy. Learn more aboutaria-disabled.:exact(boolean/0) - Since Playwright 1.28. Whether:nameand:descriptionare matched exactly: case-sensitive and whole-string. Defaults to false. Ignored when the value is a regular expression. Note that exact match still trims whitespace.:expanded(boolean/0) - An attribute that is usually set byaria-expanded.Learn more about
aria-expanded.:include_hidden(boolean/0) - Option that controls whether hidden elements are matched. By default, only non-hidden elements, as defined by ARIA, are matched by role selector.Learn more about
aria-hidden.:level(integer/0) - A number attribute that is usually present for rolesheading,listitem,row,treeitem, with default values for<h1>-<h6>elements.Learn more about
aria-level.:name(String.t/0|Regex.t/0|Playwright.RegExp.t/0) - Option to match the accessible name. By default, matching is case-insensitive and searches for a substring, use:exactto control this behavior.Learn more about accessible name.
:pressed(boolean/0) - An attribute that is usually set byaria-pressed.Learn more about
aria-pressed.:selected(boolean/0) - An attribute that is usually set byaria-selected.Learn more about
aria-selected.
@spec get_by_test_id(t(), String.t() | Regex.t() | Playwright.RegExp.t()) :: Playwright.Locator.t()
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 its test id:
Page.get_by_test_id(page, "directions") |> Locator.click!()Details
By default, the data-testid attribute is used as a test id. Use Playwright.Selectors.set_test_id_attribute/2 to configure a different test id attribute if necessary.
# Set a custom test id attribute:
Playwright.selectors(playwright) |> Selectors.set_test_id_attribute("data-pw")Since Playwright 1.27.
Arguments
test_id- Id to locate the element by.
@spec get_by_text( t(), String.t() | Regex.t() | Playwright.RegExp.t(), get_by_text_options() ) :: Playwright.Locator.t()
Allows locating elements that contain given text.
See also Playwright.Locator.filter/2 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:
# Matches <span>
Page.get_by_text(page, "world")
# Matches first <div>
Page.get_by_text(page, "Hello world")
# Matches second <div>
Page.get_by_text(page, "Hello", exact: true)
# Matches both <div>s
Page.get_by_text(page, ~r/Hello/)
# Matches second <div>
Page.get_by_text(page, ~r/^hello$/i)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">.
Since Playwright 1.27.
Arguments
text- Text to locate the element for.
Options
:exact(boolean/0) - 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 get_by_title( t(), String.t() | Regex.t() | Playwright.RegExp.t(), get_by_title_options() ) :: Playwright.Locator.t()
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:
Page.get_by_title(page, "Issues count") |> Expect.to_have_text!("25 issues")Since Playwright 1.27.
Arguments
text- Text to locate the element for.
Options
:exact(boolean/0) - 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 go_back(t(), go_back_options()) :: {:ok, nil | Playwright.Response.t()} | {:error, Playwright.error()}
Returns the main resource response. In case of multiple redirects, the navigation returns the response of the
last redirect. If cannot go back, returns nil.
Navigate to the previous page in history.
Warning
Testing Back/Forward Cache (BFCache) is not supported.
By default, Playwright disables the Back/Forward Cache across all browsers. Even if explicitly enabled, Playwright's internal state relies on network-level navigation events. Because BFCache restores unfreeze the DOM without firing these events, using Playwright.Page.go_back/2 or Playwright.Page.go_forward/2 to trigger a BFCache restore will result in timeouts and a desynchronized Page state.
Since Playwright 1.8.
Options
:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. Allows to cancel the operation using anAbortSignal. If the signal is aborted, the operation will be aborted and fail. Note that providing a signal does not disable the default timeout, which can be changed usingPlaywright.BrowserContext.set_default_timeout/2orPlaywright.Page.set_default_timeout/2; passtimeout: 0to disable the timeout entirely.In Elixir, a
Playwright.AbortSignal(Playwright.AbortController.signal/1).:timeout(number/0|:infinity) - Maximum operation time in milliseconds, defaults to 30 seconds, pass0to disable timeout. The default value can be changed by using thePlaywright.BrowserContext.set_default_navigation_timeout/2,Playwright.BrowserContext.set_default_timeout/2,Playwright.Page.set_default_navigation_timeout/2orPlaywright.Page.set_default_timeout/2methods.In Elixir,
:infinityis the same as0: no timeout.:wait_until(:load|:domcontentloaded|:networkidle|:commit) - When to consider operation succeeded, defaults to:load. Events can be either::domcontentloaded- consider operation to be finished when theDOMContentLoadedevent is fired.:load- consider operation to be finished when theloadevent is fired.:networkidle- DISCOURAGED consider operation to be finished when there are no network connections for at least500ms. Don't use this method for testing, rely on web assertions to assess readiness instead.:commit- consider operation to be finished when network response is received and the document started loading.
@spec go_back!(t(), go_back_options()) :: nil | Playwright.Response.t()
Like go_back/2, but returns the value and raises on error.
@spec go_forward(t(), go_forward_options()) :: {:ok, nil | Playwright.Response.t()} | {:error, Playwright.error()}
Returns the main resource response. In case of multiple redirects, the navigation returns the response of the
last redirect. If cannot go forward, returns nil.
Navigate to the next page in history.
Warning
Testing Back/Forward Cache (BFCache) is not supported.
By default, Playwright disables the Back/Forward Cache across all browsers. Even if explicitly enabled, Playwright's internal state relies on network-level navigation events. Because BFCache restores unfreeze the DOM without firing these events, using Playwright.Page.go_back/2 or Playwright.Page.go_forward/2 to trigger a BFCache restore will result in timeouts and a desynchronized Page state.
Since Playwright 1.8.
Options
:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. Allows to cancel the operation using anAbortSignal. If the signal is aborted, the operation will be aborted and fail. Note that providing a signal does not disable the default timeout, which can be changed usingPlaywright.BrowserContext.set_default_timeout/2orPlaywright.Page.set_default_timeout/2; passtimeout: 0to disable the timeout entirely.In Elixir, a
Playwright.AbortSignal(Playwright.AbortController.signal/1).:timeout(number/0|:infinity) - Maximum operation time in milliseconds, defaults to 30 seconds, pass0to disable timeout. The default value can be changed by using thePlaywright.BrowserContext.set_default_navigation_timeout/2,Playwright.BrowserContext.set_default_timeout/2,Playwright.Page.set_default_navigation_timeout/2orPlaywright.Page.set_default_timeout/2methods.In Elixir,
:infinityis the same as0: no timeout.:wait_until(:load|:domcontentloaded|:networkidle|:commit) - When to consider operation succeeded, defaults to:load. Events can be either::domcontentloaded- consider operation to be finished when theDOMContentLoadedevent is fired.:load- consider operation to be finished when theloadevent is fired.:networkidle- DISCOURAGED consider operation to be finished when there are no network connections for at least500ms. Don't use this method for testing, rely on web assertions to assess readiness instead.:commit- consider operation to be finished when network response is received and the document started loading.
@spec go_forward!(t(), go_forward_options()) :: nil | Playwright.Response.t()
Like go_forward/2, but returns the value and raises on error.
@spec goto(t(), String.t(), goto_options()) :: {:ok, nil | Playwright.Response.t()} | {:error, Playwright.error()}
Returns the main resource response. In case of multiple redirects, the navigation returns the first non-redirect response.
The method will fail if:
- there's an SSL error (e.g. in case of self-signed certificates).
- target URL is invalid.
- the
:timeoutis exceeded during navigation. - the remote server does not respond or is unreachable.
- the main resource failed to load.
The method will not fail 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
Playwright.Response.status/1.
Note
The method either fails 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 nil.
Note
Headless mode doesn't support navigation to a PDF document. See the upstream issue.
Since Playwright 1.8.
Arguments
url- URL to navigate page to. The url should include scheme, e.g.https://. When a:base_urlvia the context options was provided and the passed URL is a path, it gets merged via thenew URL()constructor.
Options
:referer(String.t/0) - Referer header value. If provided it will take preference over the referer header value set byPlaywright.Page.set_extra_http_headers/2.:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. Allows to cancel the operation using anAbortSignal. If the signal is aborted, the operation will be aborted and fail. Note that providing a signal does not disable the default timeout, which can be changed usingPlaywright.BrowserContext.set_default_timeout/2orPlaywright.Page.set_default_timeout/2; passtimeout: 0to disable the timeout entirely.In Elixir, a
Playwright.AbortSignal(Playwright.AbortController.signal/1).:timeout(number/0|:infinity) - Maximum operation time in milliseconds, defaults to 30 seconds, pass0to disable timeout. The default value can be changed by using thePlaywright.BrowserContext.set_default_navigation_timeout/2,Playwright.BrowserContext.set_default_timeout/2,Playwright.Page.set_default_navigation_timeout/2orPlaywright.Page.set_default_timeout/2methods.In Elixir,
:infinityis the same as0: no timeout.:wait_until(:load|:domcontentloaded|:networkidle|:commit) - When to consider operation succeeded, defaults to:load. Events can be either::domcontentloaded- consider operation to be finished when theDOMContentLoadedevent is fired.:load- consider operation to be finished when theloadevent is fired.:networkidle- DISCOURAGED consider operation to be finished when there are no network connections for at least500ms. Don't use this method for testing, rely on web assertions to assess readiness instead.:commit- consider operation to be finished when network response is received and the document started loading.
@spec goto!(t(), String.t(), goto_options()) :: nil | Playwright.Response.t()
Like goto/3, but returns the value and raises on error.
@spec hide_highlight(t()) :: :ok | {:error, Playwright.error()}
Hide all locator highlight overlays previously added by Playwright.Locator.highlight/2 on this page.
Since Playwright 1.60.
@spec hide_highlight!(t()) :: :ok
Like hide_highlight/1, but returns the value and raises on error.
@spec hover(t(), String.t(), hover_options()) :: :ok | {:error, Playwright.error()}
This method hovers over an element matching selector by performing the following steps:
- Find an element matching
selector. If there is none, wait until a matching element is attached to the DOM. - Wait for actionability checks on the matched element, unless
:forceoption 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/1to hover over the center of the element, or the specified:position.
When all steps combined have not finished during the specified :timeout, this method fails with a
TimeoutError. Passing zero timeout disables this.
Discouraged
Use locator-based Playwright.Locator.hover/2 instead. Read more about locators.
Since Playwright 1.8.
Arguments
selector- A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.
Options
:force(boolean/0) - Whether to bypass the actionability checks. Defaults tofalse.:modifiers(list of:alt|:control|:control_or_meta|: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. "ControlOrMeta" resolves to "Control" on Windows and Linux and to "Meta" on macOS.:no_wait_after(boolean/0) - Since Playwright 1.28. This option has no effect.:position(map/0) - A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of the element.:x:y
:scroll(:auto|:none) - Since Playwright 1.62. Controls whether Playwright scrolls the element into view before performing the action. Defaults to:auto, which scrolls the element into view when necessary, including scrolling nested scrollable containers. When set to:none, Playwright does not scroll the element and the action fails if the element is not already in the viewport. This is useful to assert that an element is reachable by the user without additional scrolling.:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. Allows to cancel the operation using anAbortSignal. If the signal is aborted, the operation will be aborted and fail. Note that providing a signal does not disable the default timeout, which can be changed usingPlaywright.BrowserContext.set_default_timeout/2orPlaywright.Page.set_default_timeout/2; passtimeout: 0to disable the timeout entirely.In Elixir, a
Playwright.AbortSignal(Playwright.AbortController.signal/1).:strict(boolean/0) - Since Playwright 1.14. When true, the call requires selector to resolve to a single element. If given selector resolves to more than one element, the call fails.:timeout(number/0|:infinity) - Maximum time in milliseconds. Defaults to30000(30 seconds). Pass0to disable timeout. The default value can be changed by using thePlaywright.BrowserContext.set_default_timeout/2orPlaywright.Page.set_default_timeout/2methods.In Elixir,
:infinityis the same as0: no timeout.:trial(boolean/0) - Since Playwright 1.11. When set, this method only performs the actionability checks and skips the action. Defaults tofalse. Useful to wait until the element is ready for the action without performing it. Note that keyboard:modifierswill be pressed regardless of:trialto allow testing elements which are only visible when those keys are pressed.
@spec hover!(t(), String.t(), hover_options()) :: :ok
Like hover/3, but returns the value and raises on error.
@spec inner_html(t(), String.t(), inner_html_options()) :: {:ok, String.t()} | {:error, Playwright.error()}
Returns element.innerHTML.
Discouraged
Use locator-based Playwright.Locator.inner_html/2 instead. Read more about locators.
Since Playwright 1.8.
Arguments
selector- A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.
Options
:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. Allows to cancel the operation using anAbortSignal. If the signal is aborted, the operation will be aborted and fail. Note that providing a signal does not disable the default timeout, which can be changed usingPlaywright.BrowserContext.set_default_timeout/2orPlaywright.Page.set_default_timeout/2; passtimeout: 0to disable the timeout entirely.In Elixir, a
Playwright.AbortSignal(Playwright.AbortController.signal/1).:strict(boolean/0) - Since Playwright 1.14. When true, the call requires selector to resolve to a single element. If given selector resolves to more than one element, the call fails.:timeout(number/0|:infinity) - Maximum time in milliseconds. Defaults to30000(30 seconds). Pass0to disable timeout. The default value can be changed by using thePlaywright.BrowserContext.set_default_timeout/2orPlaywright.Page.set_default_timeout/2methods.In Elixir,
:infinityis the same as0: no timeout.
@spec inner_html!(t(), String.t(), inner_html_options()) :: String.t()
Like inner_html/3, but returns the value and raises on error.
@spec inner_text(t(), String.t(), inner_text_options()) :: {:ok, String.t()} | {:error, Playwright.error()}
Returns element.innerText.
Discouraged
Use locator-based Playwright.Locator.inner_text/2 instead. Read more about locators.
Since Playwright 1.8.
Arguments
selector- A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.
Options
:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. Allows to cancel the operation using anAbortSignal. If the signal is aborted, the operation will be aborted and fail. Note that providing a signal does not disable the default timeout, which can be changed usingPlaywright.BrowserContext.set_default_timeout/2orPlaywright.Page.set_default_timeout/2; passtimeout: 0to disable the timeout entirely.In Elixir, a
Playwright.AbortSignal(Playwright.AbortController.signal/1).:strict(boolean/0) - Since Playwright 1.14. When true, the call requires selector to resolve to a single element. If given selector resolves to more than one element, the call fails.:timeout(number/0|:infinity) - Maximum time in milliseconds. Defaults to30000(30 seconds). Pass0to disable timeout. The default value can be changed by using thePlaywright.BrowserContext.set_default_timeout/2orPlaywright.Page.set_default_timeout/2methods.In Elixir,
:infinityis the same as0: no timeout.
@spec inner_text!(t(), String.t(), inner_text_options()) :: String.t()
Like inner_text/3, but returns the value and raises on error.
@spec input_value(t(), String.t(), input_value_options()) :: {:ok, String.t()} | {:error, Playwright.error()}
Returns input.value for the selected <input> or <textarea> or <select> element.
Fails for non-input elements. However, if the element is inside the <label> element that has an associated control, returns the value of the control.
Discouraged
Use locator-based Playwright.Locator.input_value/2 instead. Read more about locators.
Since Playwright 1.13.
Arguments
selector- A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.
Options
:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. Allows to cancel the operation using anAbortSignal. If the signal is aborted, the operation will be aborted and fail. Note that providing a signal does not disable the default timeout, which can be changed usingPlaywright.BrowserContext.set_default_timeout/2orPlaywright.Page.set_default_timeout/2; passtimeout: 0to disable the timeout entirely.In Elixir, a
Playwright.AbortSignal(Playwright.AbortController.signal/1).:strict(boolean/0) - Since Playwright 1.14. When true, the call requires selector to resolve to a single element. If given selector resolves to more than one element, the call fails.:timeout(number/0|:infinity) - Maximum time in milliseconds. Defaults to30000(30 seconds). Pass0to disable timeout. The default value can be changed by using thePlaywright.BrowserContext.set_default_timeout/2orPlaywright.Page.set_default_timeout/2methods.In Elixir,
:infinityis the same as0: no timeout.
@spec input_value!(t(), String.t(), input_value_options()) :: String.t()
Like input_value/3, but returns the value and raises on error.
@spec is_checked(t(), String.t(), is_checked_options()) :: {:ok, boolean()} | {:error, Playwright.error()}
Returns whether the element is checked. Fails if the element is not a checkbox or radio input.
Discouraged
Use locator-based Playwright.Locator.is_checked/2 instead. Read more about locators.
Since Playwright 1.8.
Arguments
selector- A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.
Options
:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. Allows to cancel the operation using anAbortSignal. If the signal is aborted, the operation will be aborted and fail. Note that providing a signal does not disable the default timeout, which can be changed usingPlaywright.BrowserContext.set_default_timeout/2orPlaywright.Page.set_default_timeout/2; passtimeout: 0to disable the timeout entirely.In Elixir, a
Playwright.AbortSignal(Playwright.AbortController.signal/1).:strict(boolean/0) - Since Playwright 1.14. When true, the call requires selector to resolve to a single element. If given selector resolves to more than one element, the call fails.:timeout(number/0|:infinity) - Maximum time in milliseconds. Defaults to30000(30 seconds). Pass0to disable timeout. The default value can be changed by using thePlaywright.BrowserContext.set_default_timeout/2orPlaywright.Page.set_default_timeout/2methods.In Elixir,
:infinityis the same as0: no timeout.
@spec is_checked!(t(), String.t(), is_checked_options()) :: boolean()
Like is_checked/3, but returns the value and raises on error.
Indicates that the page has been closed.
Since Playwright 1.8.
@spec is_disabled(t(), String.t(), is_disabled_options()) :: {:ok, boolean()} | {:error, Playwright.error()}
Returns whether the element is disabled, the opposite of enabled.
Discouraged
Use locator-based Playwright.Locator.is_disabled/2 instead. Read more about locators.
Since Playwright 1.8.
Arguments
selector- A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.
Options
:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. Allows to cancel the operation using anAbortSignal. If the signal is aborted, the operation will be aborted and fail. Note that providing a signal does not disable the default timeout, which can be changed usingPlaywright.BrowserContext.set_default_timeout/2orPlaywright.Page.set_default_timeout/2; passtimeout: 0to disable the timeout entirely.In Elixir, a
Playwright.AbortSignal(Playwright.AbortController.signal/1).:strict(boolean/0) - Since Playwright 1.14. When true, the call requires selector to resolve to a single element. If given selector resolves to more than one element, the call fails.:timeout(number/0|:infinity) - Maximum time in milliseconds. Defaults to30000(30 seconds). Pass0to disable timeout. The default value can be changed by using thePlaywright.BrowserContext.set_default_timeout/2orPlaywright.Page.set_default_timeout/2methods.In Elixir,
:infinityis the same as0: no timeout.
@spec is_disabled!(t(), String.t(), is_disabled_options()) :: boolean()
Like is_disabled/3, but returns the value and raises on error.
@spec is_editable(t(), String.t(), is_editable_options()) :: {:ok, boolean()} | {:error, Playwright.error()}
Returns whether the element is editable.
Discouraged
Use locator-based Playwright.Locator.is_editable/2 instead. Read more about locators.
Since Playwright 1.8.
Arguments
selector- A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.
Options
:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. Allows to cancel the operation using anAbortSignal. If the signal is aborted, the operation will be aborted and fail. Note that providing a signal does not disable the default timeout, which can be changed usingPlaywright.BrowserContext.set_default_timeout/2orPlaywright.Page.set_default_timeout/2; passtimeout: 0to disable the timeout entirely.In Elixir, a
Playwright.AbortSignal(Playwright.AbortController.signal/1).:strict(boolean/0) - Since Playwright 1.14. When true, the call requires selector to resolve to a single element. If given selector resolves to more than one element, the call fails.:timeout(number/0|:infinity) - Maximum time in milliseconds. Defaults to30000(30 seconds). Pass0to disable timeout. The default value can be changed by using thePlaywright.BrowserContext.set_default_timeout/2orPlaywright.Page.set_default_timeout/2methods.In Elixir,
:infinityis the same as0: no timeout.
@spec is_editable!(t(), String.t(), is_editable_options()) :: boolean()
Like is_editable/3, but returns the value and raises on error.
@spec is_enabled(t(), String.t(), is_enabled_options()) :: {:ok, boolean()} | {:error, Playwright.error()}
Returns whether the element is enabled.
Discouraged
Use locator-based Playwright.Locator.is_enabled/2 instead. Read more about locators.
Since Playwright 1.8.
Arguments
selector- A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.
Options
:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. Allows to cancel the operation using anAbortSignal. If the signal is aborted, the operation will be aborted and fail. Note that providing a signal does not disable the default timeout, which can be changed usingPlaywright.BrowserContext.set_default_timeout/2orPlaywright.Page.set_default_timeout/2; passtimeout: 0to disable the timeout entirely.In Elixir, a
Playwright.AbortSignal(Playwright.AbortController.signal/1).:strict(boolean/0) - Since Playwright 1.14. When true, the call requires selector to resolve to a single element. If given selector resolves to more than one element, the call fails.:timeout(number/0|:infinity) - Maximum time in milliseconds. Defaults to30000(30 seconds). Pass0to disable timeout. The default value can be changed by using thePlaywright.BrowserContext.set_default_timeout/2orPlaywright.Page.set_default_timeout/2methods.In Elixir,
:infinityis the same as0: no timeout.
@spec is_enabled!(t(), String.t(), is_enabled_options()) :: boolean()
Like is_enabled/3, but returns the value and raises on error.
@spec is_visible(t(), String.t(), is_visible_options()) :: {:ok, boolean()} | {:error, Playwright.error()}
Returns whether the element is visible. selector that does not match any elements is considered not visible.
Discouraged
Use locator-based Playwright.Locator.is_visible/2 instead. Read more about locators.
Since Playwright 1.8.
Arguments
selector- A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.
Options
:strict(boolean/0) - Since Playwright 1.14. When true, the call requires selector to resolve to a single element. If given selector resolves to more than one element, the call fails.:timeout(number/0|:infinity) - This option is ignored.Playwright.Page.is_visible/3does not wait for the element to become visible and returns immediately.
@spec is_visible!(t(), String.t(), is_visible_options()) :: boolean()
Like is_visible/3, but returns the value and raises on error.
@spec keyboard(t()) :: Playwright.Keyboard.t()
Since Playwright 1.8.
@spec local_storage(t()) :: Playwright.WebStorage.t()
Provides access to the page's localStorage for the current origin. See WebStorage.
Page.local_storage(page) |> WebStorage.set_item!("token", "abc")
token = Page.local_storage(page) |> WebStorage.get_item!("token")Since Playwright 1.61.
@spec locator(t(), String.t(), locator_options()) :: Playwright.Locator.t()
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.
Since Playwright 1.14.
Arguments
selector- A selector to use when resolving DOM element.
Options
:has(Playwright.Locator.t/0) - Narrows down the results of the method to those which contain elements matching this relative locator. For example,articlethat hastext=Playwrightmatches<article><div>Playwright</div></article>.Inner locator must be relative to the outer locator and is queried starting with the outer locator match, not the document root. For example, you can find
contentthat hasdivin<article><content><div>Playwright</div></content></article>. However, looking forcontentthat hasarticle divwill fail, because the inner locator must be relative and should not use any elements outside thecontent.Note that outer and inner locators must belong to the same frame. Inner locator must not contain
FrameLocators.:has_not(Playwright.Locator.t/0) - Since Playwright 1.33. Matches elements that do not contain an element that matches an inner locator. Inner locator is queried against the outer one. For example,articlethat does not havedivmatches<article><span>Playwright</span></article>.Note that outer and inner locators must belong to the same frame. Inner locator must not contain
FrameLocators.:has_not_text(String.t/0|Regex.t/0|Playwright.RegExp.t/0) - Since Playwright 1.33. Matches elements that do not contain specified text somewhere inside, possibly in a child or a descendant element. When passed astring, matching is case-insensitive and searches for a substring.:has_text(String.t/0|Regex.t/0|Playwright.RegExp.t/0) - Matches elements containing specified text somewhere inside, possibly in a child or a descendant element. When passed astring, matching is case-insensitive and searches for a substring. For example,"Playwright"matches<article><div>Playwright</div></article>.
@spec main_frame(t()) :: Playwright.Frame.t()
The page's main frame. Page is guaranteed to have a main frame which persists during navigations.
Since Playwright 1.8.
@spec mouse(t()) :: Playwright.Mouse.t()
Since Playwright 1.8.
@spec opener(t()) :: {:ok, nil | t()} | {:error, Playwright.error()}
Returns the opener for popup pages and nil for others. If the opener has been closed already the returns nil.
Since Playwright 1.8.
Like opener/1, but returns the value and raises on error.
@spec page_errors(t(), page_errors_options()) :: {:ok, [Exception.t()]} | {:error, Playwright.error()}
Returns up to (currently) 200 last page errors from this page. See Page.on(:page_error) for more details.
Since Playwright 1.56.
Options
:filter(:all|:since_navigation) - Since Playwright 1.59. Controls which errors are returned:
@spec page_errors!(t(), page_errors_options()) :: [Exception.t()]
Like page_errors/2, but returns the value and raises on error.
@spec pause(t()) :: :ok | {:error, Playwright.error()}
Pauses script execution. Playwright will stop executing the script and wait for the user to either press the 'Resume'
button in the page overlay or to call playwright.resume() in the DevTools console.
User can inspect selectors or perform manual steps while paused. Resume will continue running the original script from the place it was paused.
Note
This method requires Playwright to be started in a headed mode, with a falsy headless option.
Since Playwright 1.9.
@spec pause!(t()) :: :ok
Like pause/1, but returns the value and raises on error.
@spec pdf(t(), pdf_options()) :: {:ok, binary()} | {:error, Playwright.error()}
Returns the PDF buffer.
Playwright.Page.pdf/2 generates a pdf of the page with print css media. To generate a pdf with screen media, call
Playwright.Page.emulate_media/2 before calling Playwright.Page.pdf/2:
Note
By default, Playwright.Page.pdf/2 generates a pdf with modified colors for printing. Use the
-webkit-print-color-adjust property to
force rendering of exact colors.
Usage
# Generates a PDF with "screen" media type.
Page.emulate_media!(page, media: :screen)
Page.pdf!(page, path: "page.pdf")The :width, :height, and :margin options accept values labeled with units. Unlabeled
values are treated as pixels.
A few examples:
Page.pdf(page, width: 100)- prints with width set to 100 pixelsPage.pdf(page, width: "100px")- prints with width set to 100 pixelsPage.pdf(page, width: "10cm")- prints with width set to 10 centimeters.
All possible units are:
px- pixelin- inchcm- centimetermm- millimeter
The :format options are:
Letter: 8.5in x 11inLegal: 8.5in x 14inTabloid: 11in x 17inLedger: 17in x 11inA0: 33.1in x 46.8inA1: 23.4in x 33.1inA2: 16.54in x 23.4inA3: 11.7in x 16.54inA4: 8.27in x 11.7inA5: 5.83in x 8.27inA6: 4.13in x 5.83in
Note
:header_template and :footer_template markup have the following limitations: > 1. Script tags inside
templates are not evaluated. > 2. Page styles are not visible inside templates.
Since Playwright 1.8.
Options
:display_header_footer(boolean/0) - Display header and footer. Defaults tofalse.:footer_template(String.t/0) - HTML template for the print footer. Should use the same format as the:header_template.:format(String.t/0) - Paper format. If set, takes priority over:widthor:heightoptions. Defaults to 'Letter'.:header_template(String.t/0) - HTML template for the print header. Should be valid HTML markup with following classes used to inject printing values into them:'date'formatted print date'title'document title'url'document location'pageNumber'current page number'totalPages'total pages in the document
:height(String.t/0|number/0) - Paper height, accepts values labeled with units.:landscape(boolean/0) - Paper orientation. Defaults tofalse.:margin(map/0) - Paper margins, defaults to none.:top- Top margin, accepts values labeled with units. Defaults to0.:right- Right margin, accepts values labeled with units. Defaults to0.:bottom- Bottom margin, accepts values labeled with units. Defaults to0.:left- Left margin, accepts values labeled with units. Defaults to0.
:outline(boolean/0) - Since Playwright 1.42. Whether or not to embed the document outline into the PDF. Defaults tofalse.:page_ranges(String.t/0) - Paper ranges to print, e.g., '1-5, 8, 11-13'. Defaults to the empty string, which means print all pages.:path(String.t/0) - The file path to save the PDF to. If:pathis a relative path, then it is resolved relative to the current working directory. If no path is provided, the PDF won't be saved to the disk.:prefer_css_page_size(boolean/0) - Give any CSS@pagesize declared in the page priority over what is declared in:widthand:heightor:formatoptions. Defaults tofalse, which will scale the content to fit the paper size.:print_background(boolean/0) - Print background graphics. Defaults tofalse.:scale(number/0) - Scale of the webpage rendering. Defaults to1. Scale amount must be between 0.1 and 2.:tagged(boolean/0) - Since Playwright 1.42. Whether or not to generate tagged (accessible) PDF. Defaults tofalse.:width(String.t/0|number/0) - Paper width, accepts values labeled with units.
@spec pdf!(t(), pdf_options()) :: binary()
Like pdf/2, but returns the value and raises on error.
@spec pick_locator(t()) :: {:ok, Playwright.Locator.t()} | {:error, Playwright.error()}
Enters pick locator mode where hovering over page elements highlights them and shows the corresponding locator.
Once the user clicks an element, the mode is deactivated and the Locator for the picked element is returned.
Usage
locator = Page.pick_locator!(page)
IO.puts(Locator.to_string(locator))Since Playwright 1.59.
@spec pick_locator!(t()) :: Playwright.Locator.t()
Like pick_locator/1, but returns the value and raises on error.
@spec press(t(), String.t(), String.t(), press_options()) :: :ok | {:error, Playwright.error()}
Focuses the element, and then uses Playwright.Keyboard.down/2 and Playwright.Keyboard.up/2.
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.
Usage
page = Browser.new_page!(browser)
Page.goto!(page, "https://keycode.info")
Page.press!(page, "body", "A")
Page.screenshot!(page, path: "A.png")
Page.press!(page, "body", "ArrowLeft")
Page.screenshot!(page, path: "ArrowLeft.png")
Page.press!(page, "body", "Shift+O")
Page.screenshot!(page, path: "O.png")
Browser.close!(browser)Discouraged
Use locator-based Playwright.Locator.press/3 instead. Read more about locators.
Since Playwright 1.8.
Arguments
selector- A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.key- Name of the key to press or a character to generate, such asArrowLeftora.
Options
:delay(number/0) - Time to wait betweenkeydownandkeyupin milliseconds. Defaults to 0.:no_wait_after(boolean/0) - 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. Defaults tofalse.:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. Allows to cancel the operation using anAbortSignal. If the signal is aborted, the operation will be aborted and fail. Note that providing a signal does not disable the default timeout, which can be changed usingPlaywright.BrowserContext.set_default_timeout/2orPlaywright.Page.set_default_timeout/2; passtimeout: 0to disable the timeout entirely.In Elixir, a
Playwright.AbortSignal(Playwright.AbortController.signal/1).:strict(boolean/0) - Since Playwright 1.14. When true, the call requires selector to resolve to a single element. If given selector resolves to more than one element, the call fails.:timeout(number/0|:infinity) - Maximum time in milliseconds. Defaults to30000(30 seconds). Pass0to disable timeout. The default value can be changed by using thePlaywright.BrowserContext.set_default_timeout/2orPlaywright.Page.set_default_timeout/2methods.In Elixir,
:infinityis the same as0: no timeout.
@spec press!(t(), String.t(), String.t(), press_options()) :: :ok
Like press/4, but returns the value and raises on error.
@spec query_selector(t(), String.t(), query_selector_options()) :: {:ok, nil | Playwright.ElementHandle.t()} | {:error, Playwright.error()}
The method finds an element matching the specified selector within the page. If no elements match the selector, the
return value is nil. To wait for an element on the page, use Playwright.Locator.wait_for/2.
Discouraged
Use locator-based Playwright.Page.locator/3 instead. Read more about locators.
Since Playwright 1.9.
Arguments
selector- A selector to query for.
Options
:strict(boolean/0) - Since Playwright 1.14. When true, the call requires selector to resolve to a single element. If given selector resolves to more than one element, the call fails.
@spec query_selector!(t(), String.t(), query_selector_options()) :: nil | Playwright.ElementHandle.t()
Like query_selector/3, but returns the value and raises on error.
@spec query_selector_all(t(), String.t()) :: {:ok, [Playwright.ElementHandle.t()]} | {:error, Playwright.error()}
The method finds all elements matching the specified selector within the page. If no elements match the selector, the
return value is [].
Discouraged
Use locator-based Playwright.Page.locator/3 instead. Read more about locators.
Since Playwright 1.9.
Arguments
selector- A selector to query for.
@spec query_selector_all!(t(), String.t()) :: [Playwright.ElementHandle.t()]
Like query_selector_all/2, but returns the value and raises on error.
@spec reload(t(), reload_options()) :: {:ok, nil | Playwright.Response.t()} | {:error, Playwright.error()}
This method reloads the current page, in the same way as if the user had triggered a browser refresh. Returns the main resource response. In case of multiple redirects, the navigation returns the response of the last redirect.
Since Playwright 1.8.
Options
:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. Allows to cancel the operation using anAbortSignal. If the signal is aborted, the operation will be aborted and fail. Note that providing a signal does not disable the default timeout, which can be changed usingPlaywright.BrowserContext.set_default_timeout/2orPlaywright.Page.set_default_timeout/2; passtimeout: 0to disable the timeout entirely.In Elixir, a
Playwright.AbortSignal(Playwright.AbortController.signal/1).:timeout(number/0|:infinity) - Maximum operation time in milliseconds, defaults to 30 seconds, pass0to disable timeout. The default value can be changed by using thePlaywright.BrowserContext.set_default_navigation_timeout/2,Playwright.BrowserContext.set_default_timeout/2,Playwright.Page.set_default_navigation_timeout/2orPlaywright.Page.set_default_timeout/2methods.In Elixir,
:infinityis the same as0: no timeout.:wait_until(:load|:domcontentloaded|:networkidle|:commit) - When to consider operation succeeded, defaults to:load. Events can be either::domcontentloaded- consider operation to be finished when theDOMContentLoadedevent is fired.:load- consider operation to be finished when theloadevent is fired.:networkidle- DISCOURAGED consider operation to be finished when there are no network connections for at least500ms. Don't use this method for testing, rely on web assertions to assess readiness instead.:commit- consider operation to be finished when network response is received and the document started loading.
@spec reload!(t(), reload_options()) :: nil | Playwright.Response.t()
Like reload/2, but returns the value and raises on error.
@spec remove_all_listeners( t(), event() | String.t() | nil, remove_all_listeners_options() ) :: :ok | {:error, Playwright.error()}
Removes all the listeners of the given type (or all registered listeners if no type given). Allows to wait for running listeners to complete or to ignore subsequent errors from these listeners.
Usage
Page.on(page, :request, fn request ->
response = Request.response!(request)
body = Response.body!(response)
IO.puts(byte_size(body))
end)
Page.goto!(page, "https://playwright.dev", wait_until: :domcontentloaded)
# Waits for all the reported :request events to resolve.
Page.remove_all_listeners!(page, :request, behavior: :wait)Since Playwright 1.47.
Options
The options may take the place of event, which is then nil.
:behavior(:wait|:ignore_errors|:default) - Specifies whether to wait for already running listeners and what to do if they raise::default- do not wait for current listener calls (if any) to finish, if the listener raises, it may result in unhandled error:wait- wait for current listener calls (if any) to finish:ignore_errors- do not wait for current listener calls (if any) to finish, all errors raised by the listeners after removal are silently caught
@spec remove_all_listeners!( t(), event() | String.t() | nil, remove_all_listeners_options() ) :: :ok
Like remove_all_listeners/3, but returns the value and raises on error.
@spec remove_locator_handler(t(), Playwright.Locator.t()) :: :ok | {:error, Playwright.error()}
Removes all locator handlers added by Playwright.Page.add_locator_handler/4 for a specific locator.
Since Playwright 1.44.
Arguments
locator- Locator passed toPlaywright.Page.add_locator_handler/4.
@spec remove_locator_handler!(t(), Playwright.Locator.t()) :: :ok
Like remove_locator_handler/2, but returns the value and raises on error.
@spec request(t()) :: Playwright.APIRequestContext.t()
API testing helper associated with this page. This method returns the same instance as
Playwright.BrowserContext.request/1 on the page's context. See Playwright.BrowserContext.request/1 for more details.
Since Playwright 1.16.
@spec request_gc(t()) :: :ok | {:error, Playwright.error()}
Request the page to perform garbage collection. Note that there is no guarantee that all unreachable objects will be collected.
This is useful to help detect memory leaks. For example, if your page has a large object 'suspect' that might be leaked, you can check that it does not leak by using a WeakRef.
# 1. In your page, save a WeakRef for the "suspect".
Page.evaluate!(page, "() => globalThis.suspectWeakRef = new WeakRef(suspect)")
# 2. Request garbage collection.
Page.request_gc!(page)
# 3. Check that weak ref does not deref to the original object.
assert Page.evaluate!(page, "() => !globalThis.suspectWeakRef.deref()") == trueSince Playwright 1.48.
@spec request_gc!(t()) :: :ok
Like request_gc/1, but returns the value and raises on error.
@spec requests(t()) :: {:ok, [Playwright.Request.t()]} | {:error, Playwright.error()}
Returns up to (currently) 100 last network request from this page. See Page.on(:request) for more details.
Returned requests should be accessed immediately, otherwise they might be collected to prevent unbounded memory growth as new requests come in. Once collected, retrieving most information about the request is impossible.
Note that requests reported through the Page.on(:request) request are not collected, so there is a trade off between efficient memory usage with Playwright.Page.requests/1 and the amount of available information reported through Page.on(:request).
Since Playwright 1.56.
@spec requests!(t()) :: [Playwright.Request.t()]
Like requests/1, but returns the value and raises on error.
@spec route( t(), String.t() | Regex.t() | Playwright.RegExp.t() | (URI.t() -> boolean()), (Playwright.Route.t() -> term()) | (Playwright.Route.t(), Playwright.Request.t() -> term()), route_options() ) :: {:ok, Playwright.Disposable.t()} | {:error, Playwright.error()}
Routing provides the capability to modify network requests that are made by a page.
Once routing is enabled, every request matching the url pattern will stall unless it's continued, fulfilled or aborted.
Note
The handler will only be called for the first url if the response is a redirect.
Note
Playwright.Page.route/4 will not intercept requests intercepted by Service Worker. See this issue. We recommend disabling Service Workers when using request interception by setting :service_workers to :block.
Note
Playwright.Page.route/4 will not intercept the first request of a popup page. Use Playwright.BrowserContext.route/4 instead.
Usage
An example of a naive handler that aborts all image requests:
page = Browser.new_page!(browser)
Page.route!(page, "**/*.{png,jpg,jpeg}", &Route.abort!/1)
Page.goto!(page, "https://example.com")
Browser.close!(browser)or the same snippet using a regex pattern instead:
page = Browser.new_page!(browser)
Page.route!(page, ~r/(\.png$)|(\.jpg$)/, &Route.abort!/1)
Page.goto!(page, "https://example.com")
Browser.close!(browser)It is possible to examine the request to decide the route action. For example, mocking all requests that contain some post data, and leaving all other requests as is:
Page.route!(page, "/api/**", fn route ->
if Route.request(route) |> Request.post_data() |> String.contains?("my-string") do
Route.fulfill!(route, body: "mocked-data")
else
Route.continue!(route)
end
end)If a request matches multiple registered routes, the most recently registered route takes precedence.
Page routes take precedence over browser context routes (set up with Playwright.BrowserContext.route/4) when request
matches both handlers.
To remove a route with its handler you can use Playwright.Page.unroute/3.
Note
Enabling routing disables http cache.
Since Playwright 1.8.
Arguments
url- A glob pattern, regex pattern, URL pattern, or predicate that receives aURIto match during routing. If:base_urlis set in the context options and the provided URL is a string that does not start with*, it is resolved using thenew URL()constructor.handler- handler function to route the request.
Options
:times(integer/0) - Since Playwright 1.15. How often a route should be used. By default it will be used every time.
@spec route!( t(), String.t() | Regex.t() | Playwright.RegExp.t() | (URI.t() -> boolean()), (Playwright.Route.t() -> term()) | (Playwright.Route.t(), Playwright.Request.t() -> term()), route_options() ) :: Playwright.Disposable.t()
Like route/4, but returns the value and raises on error.
@spec route_from_har(t(), String.t(), route_from_har_options()) :: :ok | {:error, Playwright.error()}
If specified the network requests that are made in the page will be served from the HAR file. Read more about Replaying from HAR.
Playwright will not serve requests intercepted by Service Worker from the HAR file. See this issue. We recommend disabling Service Workers when using request interception by setting :service_workers to :block.
Since Playwright 1.23.
Arguments
har- Path to a HAR file with prerecorded network data. Ifpathis a relative path, then it is resolved relative to the current working directory.
Options
:not_found(:abort|:fallback)- If set to 'abort' any request not found in the HAR file will be aborted.
- If set to 'fallback' missing requests will be sent to the network.
Defaults to abort.
:update(boolean/0) - If specified, updates the given HAR with the actual network information instead of serving from file. The file is written to disk whenPlaywright.BrowserContext.close/2is called.:update_content(:embed|:attach) - Since Playwright 1.32. Optional setting to control resource content management. Ifattachis specified, resources are persisted as separate files or entries in the ZIP archive. Ifembedis specified, content is stored inline the HAR file.:update_mode(:full|:minimal) - Since Playwright 1.32. When set tominimal, only record information necessary for routing from HAR. This omits sizes, timing, page, cookies, security and other types of HAR information that are not used when replaying from HAR. Defaults to:minimal.:url(String.t/0|Regex.t/0|Playwright.RegExp.t/0) - A glob pattern, regular expression or predicate to match the request URL. Only requests with URL matching the pattern will be served from the HAR file. If not specified, all requests are served from the HAR file.
@spec route_from_har!(t(), String.t(), route_from_har_options()) :: :ok
Like route_from_har/3, but returns the value and raises on error.
@spec route_web_socket( t(), String.t() | Regex.t() | Playwright.RegExp.t() | (URI.t() -> boolean()), (Playwright.WebSocketRoute.t() -> term()) ) :: :ok | {:error, Playwright.error()}
This method allows to modify websocket connections that are made by the page.
Note that only WebSockets created after this method was called will be routed. It is recommended to call this method before navigating the page.
Usage
Below is an example of a simple mock that responds to a single message. See WebSocketRoute for more details and examples.
Page.route_web_socket!(page, "/ws", fn ws ->
WebSocketRoute.on_message(ws, fn message ->
if message == "request", do: WebSocketRoute.send(ws, "response")
end)
end)Since Playwright 1.48.
Arguments
url- Only WebSockets with the url matching this pattern will be routed. A string pattern can be relative to the:base_urlcontext option.handler- Handler function to route the WebSocket.
@spec route_web_socket!( t(), String.t() | Regex.t() | Playwright.RegExp.t() | (URI.t() -> boolean()), (Playwright.WebSocketRoute.t() -> term()) ) :: :ok
Like route_web_socket/3, but returns the value and raises on error.
@spec screencast(t()) :: Playwright.Screencast.t()
Screencast object associated with this page.
Usage
# Frames go to the `:on_frame` callback (Screencast has no events).
screencast = Page.screencast(page)
Screencast.start!(screencast,
on_frame: fn %{data: data} -> IO.puts("received frame, jpeg size: #{byte_size(data)}") end
)
# ... perform actions ...
Screencast.stop!(screencast)Since Playwright 1.59.
@spec screenshot(t(), screenshot_options()) :: {:ok, binary()} | {:error, Playwright.error()}
Returns the buffer with the captured screenshot.
Since Playwright 1.8.
Options
:animations(:disabled|:allow) - When set to:disabled, stops CSS animations, CSS transitions and Web Animations. Animations get different treatment depending on their duration:- finite animations are fast-forwarded to completion, so they'll fire
transitionendevent. - infinite animations are canceled to initial state, and then played over after the screenshot.
Defaults to
:allowthat leaves animations untouched.- finite animations are fast-forwarded to completion, so they'll fire
:caret(:hide|:initial) - When set to:hide, screenshot will hide text caret. When set to:initial, text caret behavior will not be changed. Defaults to:hide.:clip(map/0) - An object which specifies clipping of the resulting image.:x- x-coordinate of top-left corner of clip area:y- y-coordinate of top-left corner of clip area:width- width of clipping area:height- height of clipping area
:full_page(boolean/0) - When true, takes a screenshot of the full scrollable page, instead of the currently visible viewport. Defaults tofalse.:mask(list ofPlaywright.Locator.t/0) - Specify locators that should be masked when the screenshot is taken. Masked elements will be overlaid with a pink box#FF00FF(customized by:mask_color) that completely covers its bounding box. The mask is also applied to invisible elements, see Matching only visible elements to disable that.:mask_color(String.t/0) - Since Playwright 1.35. Specify the color of the overlay box for masked elements, in CSS color format. Default color is pink#FF00FF.:omit_background(boolean/0) - Hides default white background and allows capturing screenshots with transparency. Not applicable tojpegimages. Defaults tofalse.:path(String.t/0) - The file path to save the image to. The screenshot type will be inferred from file extension. If:pathis a relative path, then it is resolved relative to the current working directory. If no path is provided, the image won't be saved to the disk.:quality(integer/0) - The quality of the image, between 0-100. Not applicable topngimages. Forjpegthe default is80. Forwebp, a quality of100(the default) produces a lossless image, while lower values use lossy compression.:scale(:css|:device) - When set to:css, screenshot will have a single pixel per each css pixel on the page. For high-dpi devices, this will keep screenshots small. Using:deviceoption will produce a single pixel per each device pixel, so screenshots of high-dpi devices will be twice as large or even larger.Defaults to
:device.:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. Allows to cancel the operation using anAbortSignal. If the signal is aborted, the operation will be aborted and fail. Note that providing a signal does not disable the default timeout, which can be changed usingPlaywright.BrowserContext.set_default_timeout/2orPlaywright.Page.set_default_timeout/2; passtimeout: 0to disable the timeout entirely.In Elixir, a
Playwright.AbortSignal(Playwright.AbortController.signal/1).:style(String.t/0) - Since Playwright 1.41. Text of the stylesheet to apply while making the screenshot. This is where you can hide dynamic elements, make elements invisible or change their properties to help you creating repeatable screenshots. This stylesheet pierces the Shadow DOM and applies to the inner frames.:timeout(number/0|:infinity) - Maximum time in milliseconds. Defaults to30000(30 seconds). Pass0to disable timeout. The default value can be changed by using thePlaywright.BrowserContext.set_default_timeout/2orPlaywright.Page.set_default_timeout/2methods.In Elixir,
:infinityis the same as0: no timeout.:type(:png|:jpeg|:webp) - Specify screenshot type, defaults to:png.
@spec screenshot!(t(), screenshot_options()) :: binary()
Like screenshot/2, but returns the value and raises on error.
@spec select_option( t(), String.t(), :null | String.t() | Playwright.ElementHandle.t() | [String.t()] | %{ optional(:value) => String.t(), optional(:label) => String.t(), optional(:index) => integer(), optional(:valueOrLabel) => String.t() } | [Playwright.ElementHandle.t()] | [ %{ optional(:value) => String.t(), optional(:label) => String.t(), optional(:index) => integer(), optional(:valueOrLabel) => String.t() } ], select_option_options() ) :: {:ok, [String.t()]} | {:error, Playwright.error()}
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 fails. 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
Page.select_option!(page, "select#colors", "blue")
# single selection matching the label
Page.select_option!(page, "select#colors", %{label: "Blue"})
# multiple selection
Page.select_option!(page, "select#colors", ["red", "green", "blue"])Discouraged
Use locator-based Playwright.Locator.select_option/3 instead. Read more about locators.
Since Playwright 1.8.
Arguments
selector- A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.values- Options to select. If the<select>has themultipleattribute, 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.:value- Matches byoption.value. Optional.:label- Matches byoption.label. Optional.:index- Matches by the index. Optional.:valueOrLabel- Matches by value or label, as a string does. Combines such a match withindexin one list.
Options
:force(boolean/0) - Since Playwright 1.13. Whether to bypass the actionability checks. Defaults tofalse.:no_wait_after(boolean/0) - This option has no effect.:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. Allows to cancel the operation using anAbortSignal. If the signal is aborted, the operation will be aborted and fail. Note that providing a signal does not disable the default timeout, which can be changed usingPlaywright.BrowserContext.set_default_timeout/2orPlaywright.Page.set_default_timeout/2; passtimeout: 0to disable the timeout entirely.In Elixir, a
Playwright.AbortSignal(Playwright.AbortController.signal/1).:strict(boolean/0) - Since Playwright 1.14. When true, the call requires selector to resolve to a single element. If given selector resolves to more than one element, the call fails.:timeout(number/0|:infinity) - Maximum time in milliseconds. Defaults to30000(30 seconds). Pass0to disable timeout. The default value can be changed by using thePlaywright.BrowserContext.set_default_timeout/2orPlaywright.Page.set_default_timeout/2methods.In Elixir,
:infinityis the same as0: no timeout.
@spec select_option!( t(), String.t(), :null | String.t() | Playwright.ElementHandle.t() | [String.t()] | %{ optional(:value) => String.t(), optional(:label) => String.t(), optional(:index) => integer(), optional(:valueOrLabel) => String.t() } | [Playwright.ElementHandle.t()] | [ %{ optional(:value) => String.t(), optional(:label) => String.t(), optional(:index) => integer(), optional(:valueOrLabel) => String.t() } ], select_option_options() ) :: [String.t()]
Like select_option/4, but returns the value and raises on error.
@spec session_storage(t()) :: Playwright.WebStorage.t()
Provides access to the page's sessionStorage for the current origin. See WebStorage.
Page.session_storage(page) |> WebStorage.set_item!("flag", "1")
flag = Page.session_storage(page) |> WebStorage.get_item!("flag")Since Playwright 1.61.
@spec set_checked(t(), String.t(), boolean(), set_checked_options()) :: :ok | {:error, Playwright.error()}
This method checks or unchecks an element matching selector by performing the following steps:
- Find an element matching
selector. If there is none, wait until a matching element is attached to the DOM. - Ensure that matched element is a checkbox or a radio input. If not, this method fails.
- If the element already has the right checked state, this method returns immediately.
- Wait for actionability checks on the matched element, unless
:forceoption 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/1to click in the center of the element. - Ensure that the element is now checked or unchecked. If not, this method fails.
When all steps combined have not finished during the specified :timeout, this method fails with a
TimeoutError. Passing zero timeout disables this.
Discouraged
Use locator-based Playwright.Locator.set_checked/3 instead. Read more about locators.
Since Playwright 1.15.
Arguments
selector- A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.checked- Whether to check or uncheck the checkbox.
Options
:force(boolean/0) - Whether to bypass the actionability checks. Defaults tofalse.:no_wait_after(boolean/0) - This option has no effect.:position(map/0) - A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of the element.:x:y
:scroll(:auto|:none) - Since Playwright 1.62. Controls whether Playwright scrolls the element into view before performing the action. Defaults to:auto, which scrolls the element into view when necessary, including scrolling nested scrollable containers. When set to:none, Playwright does not scroll the element and the action fails if the element is not already in the viewport. This is useful to assert that an element is reachable by the user without additional scrolling.:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. Allows to cancel the operation using anAbortSignal. If the signal is aborted, the operation will be aborted and fail. Note that providing a signal does not disable the default timeout, which can be changed usingPlaywright.BrowserContext.set_default_timeout/2orPlaywright.Page.set_default_timeout/2; passtimeout: 0to disable the timeout entirely.In Elixir, a
Playwright.AbortSignal(Playwright.AbortController.signal/1).:strict(boolean/0) - When true, the call requires selector to resolve to a single element. If given selector resolves to more than one element, the call fails.:timeout(number/0|:infinity) - Maximum time in milliseconds. Defaults to30000(30 seconds). Pass0to disable timeout. The default value can be changed by using thePlaywright.BrowserContext.set_default_timeout/2orPlaywright.Page.set_default_timeout/2methods.In Elixir,
:infinityis the same as0: no timeout.:trial(boolean/0) - When set, this method only performs the actionability checks and skips the action. Defaults tofalse. Useful to wait until the element is ready for the action without performing it.
@spec set_checked!(t(), String.t(), boolean(), set_checked_options()) :: :ok
Like set_checked/4, but returns the value and raises on error.
@spec set_content(t(), String.t(), set_content_options()) :: :ok | {:error, Playwright.error()}
This method internally calls document.write(), inheriting all its specific characteristics and behaviors.
Since Playwright 1.8.
Arguments
html- HTML markup to assign to the page.
Options
:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. Allows to cancel the operation using anAbortSignal. If the signal is aborted, the operation will be aborted and fail. Note that providing a signal does not disable the default timeout, which can be changed usingPlaywright.BrowserContext.set_default_timeout/2orPlaywright.Page.set_default_timeout/2; passtimeout: 0to disable the timeout entirely.In Elixir, a
Playwright.AbortSignal(Playwright.AbortController.signal/1).:timeout(number/0|:infinity) - Maximum operation time in milliseconds, defaults to 30 seconds, pass0to disable timeout. The default value can be changed by using thePlaywright.BrowserContext.set_default_navigation_timeout/2,Playwright.BrowserContext.set_default_timeout/2,Playwright.Page.set_default_navigation_timeout/2orPlaywright.Page.set_default_timeout/2methods.In Elixir,
:infinityis the same as0: no timeout.:wait_until(:load|:domcontentloaded|:networkidle|:commit) - When to consider operation succeeded, defaults to:load. Events can be either::domcontentloaded- consider operation to be finished when theDOMContentLoadedevent is fired.:load- consider operation to be finished when theloadevent is fired.:networkidle- DISCOURAGED consider operation to be finished when there are no network connections for at least500ms. Don't use this method for testing, rely on web assertions to assess readiness instead.:commit- consider operation to be finished when network response is received and the document started loading.
@spec set_content!(t(), String.t(), set_content_options()) :: :ok
Like set_content/3, but returns the value and raises on error.
This setting will change the default maximum time for all the methods accepting timeout option.
Note
Playwright.Page.set_default_navigation_timeout/2 takes priority over Playwright.Page.set_default_timeout/2.
Since Playwright 1.8.
Arguments
timeout- Maximum time in milliseconds. Pass0to disable timeout.In Elixir,
:infinityis the same as0: no timeout.
@spec set_extra_http_headers(t(), %{optional(String.t()) => String.t()}) :: :ok | {:error, Playwright.error()}
The extra HTTP headers will be sent with every request the page initiates.
Note
Playwright.Page.set_extra_http_headers/2 does not guarantee the order of headers in the outgoing requests.
Since Playwright 1.8.
Arguments
headers- An object containing additional HTTP headers to be sent with every request. All header values must be strings.
Like set_extra_http_headers/2, but returns the value and raises on error.
@spec set_input_files( t(), String.t(), String.t() | [String.t()] | %{name: String.t(), mimeType: String.t(), buffer: binary()} | [%{name: String.t(), mimeType: String.t(), buffer: binary()}], set_input_files_options() ) :: :ok | {:error, Playwright.error()}
Sets the value of the file input to these file paths or files. If some of the files are relative paths, then they
are resolved relative to the current working directory. For empty array, clears the selected files.
For inputs with a [webkitdirectory] attribute, only a single directory path is supported.
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.
Discouraged
Use locator-based Playwright.Locator.set_input_files/3 instead. Read more about locators.
Since Playwright 1.8.
Arguments
selector- A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.files:name- File name:mimeType- File type:buffer- File content
Options
:no_wait_after(boolean/0) - This option has no effect.:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. Allows to cancel the operation using anAbortSignal. If the signal is aborted, the operation will be aborted and fail. Note that providing a signal does not disable the default timeout, which can be changed usingPlaywright.BrowserContext.set_default_timeout/2orPlaywright.Page.set_default_timeout/2; passtimeout: 0to disable the timeout entirely.In Elixir, a
Playwright.AbortSignal(Playwright.AbortController.signal/1).:strict(boolean/0) - Since Playwright 1.14. When true, the call requires selector to resolve to a single element. If given selector resolves to more than one element, the call fails.:timeout(number/0|:infinity) - Maximum time in milliseconds. Defaults to30000(30 seconds). Pass0to disable timeout. The default value can be changed by using thePlaywright.BrowserContext.set_default_timeout/2orPlaywright.Page.set_default_timeout/2methods.In Elixir,
:infinityis the same as0: no timeout.
@spec set_input_files!( t(), String.t(), String.t() | [String.t()] | %{name: String.t(), mimeType: String.t(), buffer: binary()} | [%{name: String.t(), mimeType: String.t(), buffer: binary()}], set_input_files_options() ) :: :ok
Like set_input_files/4, but returns the value and raises on error.
@spec set_viewport_size(t(), %{width: integer(), height: integer()}) :: :ok | {:error, Playwright.error()}
In the case of multiple pages in a single browser, each page can have its own viewport size. However,
Playwright.Browser.new_context/2 allows to set viewport size (and more) for all pages in the context at once.
Playwright.Page.set_viewport_size/2 will resize the page. A lot of websites don't expect phones to change size, so you should set the
viewport size before navigating to the page. Playwright.Page.set_viewport_size/2 will also reset screen size, use Playwright.Browser.new_context/2 with screen and viewport parameters if you need better control of these properties.
Usage
page = Browser.new_page!(browser)
Page.set_viewport_size!(page, %{width: 640, height: 480})
Page.goto!(page, "https://example.com")Since Playwright 1.8.
Arguments
viewport_size:width- page width in pixels.:height- page height in pixels.
Like set_viewport_size/2, but returns the value and raises on error.
@spec tap(t(), String.t(), tap_options()) :: :ok | {:error, Playwright.error()}
This method taps an element matching selector by performing the following steps:
- Find an element matching
selector. If there is none, wait until a matching element is attached to the DOM. - Wait for actionability checks on the matched element, unless
:forceoption 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.touchscreen/1to tap the center of the element, or the specified:position.
When all steps combined have not finished during the specified :timeout, this method fails with a
TimeoutError. Passing zero timeout disables this.
Note
Playwright.Page.tap/3 will fail if the :has_touch option of the browser context is false.
Discouraged
Use locator-based Playwright.Locator.tap/2 instead. Read more about locators.
Since Playwright 1.8.
Arguments
selector- A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.
Options
:force(boolean/0) - Whether to bypass the actionability checks. Defaults tofalse.:modifiers(list of:alt|:control|:control_or_meta|: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. "ControlOrMeta" resolves to "Control" on Windows and Linux and to "Meta" on macOS.:no_wait_after(boolean/0) - This option has no effect.:position(map/0) - A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of the element.:x:y
:scroll(:auto|:none) - Since Playwright 1.62. Controls whether Playwright scrolls the element into view before performing the action. Defaults to:auto, which scrolls the element into view when necessary, including scrolling nested scrollable containers. When set to:none, Playwright does not scroll the element and the action fails if the element is not already in the viewport. This is useful to assert that an element is reachable by the user without additional scrolling.:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. Allows to cancel the operation using anAbortSignal. If the signal is aborted, the operation will be aborted and fail. Note that providing a signal does not disable the default timeout, which can be changed usingPlaywright.BrowserContext.set_default_timeout/2orPlaywright.Page.set_default_timeout/2; passtimeout: 0to disable the timeout entirely.In Elixir, a
Playwright.AbortSignal(Playwright.AbortController.signal/1).:strict(boolean/0) - Since Playwright 1.14. When true, the call requires selector to resolve to a single element. If given selector resolves to more than one element, the call fails.:timeout(number/0|:infinity) - Maximum time in milliseconds. Defaults to30000(30 seconds). Pass0to disable timeout. The default value can be changed by using thePlaywright.BrowserContext.set_default_timeout/2orPlaywright.Page.set_default_timeout/2methods.In Elixir,
:infinityis the same as0: no timeout.:trial(boolean/0) - Since Playwright 1.11. When set, this method only performs the actionability checks and skips the action. Defaults tofalse. Useful to wait until the element is ready for the action without performing it. Note that keyboard:modifierswill be pressed regardless of:trialto allow testing elements which are only visible when those keys are pressed.
@spec tap!(t(), String.t(), tap_options()) :: :ok
Like tap/3, but returns the value and raises on error.
@spec text_content(t(), String.t(), text_content_options()) :: {:ok, nil | String.t()} | {:error, Playwright.error()}
Returns element.textContent.
Discouraged
Use locator-based Playwright.Locator.text_content/2 instead. Read more about locators.
Since Playwright 1.8.
Arguments
selector- A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.
Options
:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. Allows to cancel the operation using anAbortSignal. If the signal is aborted, the operation will be aborted and fail. Note that providing a signal does not disable the default timeout, which can be changed usingPlaywright.BrowserContext.set_default_timeout/2orPlaywright.Page.set_default_timeout/2; passtimeout: 0to disable the timeout entirely.In Elixir, a
Playwright.AbortSignal(Playwright.AbortController.signal/1).:strict(boolean/0) - Since Playwright 1.14. When true, the call requires selector to resolve to a single element. If given selector resolves to more than one element, the call fails.:timeout(number/0|:infinity) - Maximum time in milliseconds. Defaults to30000(30 seconds). Pass0to disable timeout. The default value can be changed by using thePlaywright.BrowserContext.set_default_timeout/2orPlaywright.Page.set_default_timeout/2methods.In Elixir,
:infinityis the same as0: no timeout.
@spec text_content!(t(), String.t(), text_content_options()) :: nil | String.t()
Like text_content/3, but returns the value and raises on error.
@spec title(t()) :: {:ok, String.t()} | {:error, Playwright.error()}
Returns the page's title.
Since Playwright 1.8.
Like title/1, but returns the value and raises on error.
@spec touchscreen(t()) :: Playwright.Touchscreen.t()
Since Playwright 1.8.
@spec type(t(), String.t(), String.t(), type_options()) :: :ok | {:error, Playwright.error()}
Sends a keydown, keypress/input, and keyup event for each character in the text. Playwright.Page.type/4 can be used to send
fine-grained keyboard events. To fill values in form fields, use Playwright.Page.fill/4.
To press a special key, like Control or ArrowDown, use Playwright.Keyboard.press/3.
Usage
Since Playwright 1.8.
Arguments
selector- A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.text- A text to type into a focused element.
Options
:delay(number/0) - Time to wait between key presses in milliseconds. Defaults to 0.:no_wait_after(boolean/0) - This option has no effect.:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. Allows to cancel the operation using anAbortSignal. If the signal is aborted, the operation will be aborted and fail. Note that providing a signal does not disable the default timeout, which can be changed usingPlaywright.BrowserContext.set_default_timeout/2orPlaywright.Page.set_default_timeout/2; passtimeout: 0to disable the timeout entirely.In Elixir, a
Playwright.AbortSignal(Playwright.AbortController.signal/1).:strict(boolean/0) - Since Playwright 1.14. When true, the call requires selector to resolve to a single element. If given selector resolves to more than one element, the call fails.:timeout(number/0|:infinity) - Maximum time in milliseconds. Defaults to30000(30 seconds). Pass0to disable timeout. The default value can be changed by using thePlaywright.BrowserContext.set_default_timeout/2orPlaywright.Page.set_default_timeout/2methods.In Elixir,
:infinityis the same as0: no timeout.
@spec type!(t(), String.t(), String.t(), type_options()) :: :ok
Like type/4, but returns the value and raises on error.
@spec uncheck(t(), String.t(), uncheck_options()) :: :ok | {:error, Playwright.error()}
This method unchecks an element matching selector by performing the following steps:
- Find an element matching
selector. If there is none, wait until a matching element is attached to the DOM. - Ensure that matched element is a checkbox or a radio input. If not, this method fails. If the element is already unchecked, this method returns immediately.
- Wait for actionability checks on the matched element, unless
:forceoption 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/1to click in the center of the element. - Ensure that the element is now unchecked. If not, this method fails.
When all steps combined have not finished during the specified :timeout, this method fails with a
TimeoutError. Passing zero timeout disables this.
Discouraged
Use locator-based Playwright.Locator.uncheck/2 instead. Read more about locators.
Since Playwright 1.8.
Arguments
selector- A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.
Options
:force(boolean/0) - Whether to bypass the actionability checks. Defaults tofalse.:no_wait_after(boolean/0) - This option has no effect.:position(map/0) - Since Playwright 1.11. A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of the element.:x:y
:scroll(:auto|:none) - Since Playwright 1.62. Controls whether Playwright scrolls the element into view before performing the action. Defaults to:auto, which scrolls the element into view when necessary, including scrolling nested scrollable containers. When set to:none, Playwright does not scroll the element and the action fails if the element is not already in the viewport. This is useful to assert that an element is reachable by the user without additional scrolling.:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. Allows to cancel the operation using anAbortSignal. If the signal is aborted, the operation will be aborted and fail. Note that providing a signal does not disable the default timeout, which can be changed usingPlaywright.BrowserContext.set_default_timeout/2orPlaywright.Page.set_default_timeout/2; passtimeout: 0to disable the timeout entirely.In Elixir, a
Playwright.AbortSignal(Playwright.AbortController.signal/1).:strict(boolean/0) - Since Playwright 1.14. When true, the call requires selector to resolve to a single element. If given selector resolves to more than one element, the call fails.:timeout(number/0|:infinity) - Maximum time in milliseconds. Defaults to30000(30 seconds). Pass0to disable timeout. The default value can be changed by using thePlaywright.BrowserContext.set_default_timeout/2orPlaywright.Page.set_default_timeout/2methods.In Elixir,
:infinityis the same as0: no timeout.:trial(boolean/0) - Since Playwright 1.11. When set, this method only performs the actionability checks and skips the action. Defaults tofalse. Useful to wait until the element is ready for the action without performing it.
@spec uncheck!(t(), String.t(), uncheck_options()) :: :ok
Like uncheck/3, but returns the value and raises on error.
@spec unroute( t(), String.t() | Regex.t() | Playwright.RegExp.t() | (URI.t() -> boolean()), (Playwright.Route.t() -> term()) | (Playwright.Route.t(), Playwright.Request.t() -> term()) | nil ) :: :ok | {:error, Playwright.error()}
Removes a route created with Playwright.Page.route/4. When handler is not specified, removes all routes for
the url.
Since Playwright 1.8.
Arguments
url- A glob pattern, regex pattern, URL pattern, or predicate receivingURIto match while routing.handler- Optional handler function to route the request.
@spec unroute!( t(), String.t() | Regex.t() | Playwright.RegExp.t() | (URI.t() -> boolean()), (Playwright.Route.t() -> term()) | (Playwright.Route.t(), Playwright.Request.t() -> term()) | nil ) :: :ok
Like unroute/3, but returns the value and raises on error.
@spec unroute_all(t(), unroute_all_options()) :: :ok | {:error, Playwright.error()}
Removes all routes created with Playwright.Page.route/4 and Playwright.Page.route_from_har/3.
Since Playwright 1.41.
Options
:behavior(:wait|:ignore_errors|:default) - Specifies whether to wait for already running handlers and what to do if they raise::default- do not wait for current handler calls (if any) to finish, if unrouted handler raises, it may result in unhandled error:wait- wait for current handler calls (if any) to finish:ignore_errors- do not wait for current handler calls (if any) to finish, all errors raised by the handlers after unrouting are silently caught
@spec unroute_all!(t(), unroute_all_options()) :: :ok
Like unroute_all/2, but returns the value and raises on error.
Since Playwright 1.8.
@spec video(t()) :: nil | Playwright.Video.t()
Video object associated with this page. Can be used to access the video file when using the :record_video context option.
Since Playwright 1.8.
Since Playwright 1.8.
@spec wait_for_event(t(), event() | String.t(), wait_for_event_options() | fun()) :: Playwright.Promise.t()
Waits for event to fire and passes its value into the predicate function. Returns when the predicate returns truthy value. Will fail if the page is closed before the event is fired. Returns the event data value.
Usage
# Start waiting for download before clicking: a promise, awaited after.
download_promise = Page.wait_for_event(page, :download)
Page.get_by_text(page, "Download file") |> Locator.click!()
download = Promise.await!(download_promise)Since Playwright 1.8.
Arguments
event- Event name, same one typically passed intoPlaywright.Page.on/3.
Options
A function in place of the options is the :predicate option.
:predicate(fun/0) - Receives the event data and returns a truthy value when the waiting should resolve.:timeout(number/0|:infinity) - Maximum time to wait for in milliseconds. Defaults to30000(30 seconds). Pass0to disable timeout. The default value can be changed withPlaywright.Page.set_default_timeout/2orPlaywright.BrowserContext.set_default_timeout/2.In Elixir,
:infinityis the same as0: no timeout.:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. Allows to cancel the waiting using anAbortSignal. If the signal is aborted, the waiting will be aborted and the operation will fail. Note that providing a signal does not disable the default timeout, which can be changed usingPlaywright.BrowserContext.set_default_timeout/2; passtimeout: 0to disable the timeout entirely.In Elixir, a
Playwright.AbortSignal(Playwright.AbortController.signal/1).
Returns a Playwright.Promise at once, with the wait already set up. Start it before the action that triggers it and await it after with Playwright.Promise.await/1:
promise = Playwright.Page.wait_for_event(page, event)
Playwright.Locator.click!(button)
value = Playwright.Promise.await!(promise)The callback form expect_event/4 runs the action:
value = Playwright.Page.expect_event!(page, event, fn -> Playwright.Locator.click!(button) end)
Like wait_for_event/3, but awaits the promise: Playwright.Promise.await!(wait_for_event(...)), the value or a raise.
Start waiting before the action
This waits from the time it is called, so it misses what the code before it triggered. Start the wait with wait_for_event/3 before the action and await it after, or use the callback form expect_event!/4:
promise = Playwright.Page.wait_for_event(page, event)
Playwright.Locator.click!(button)
value = Playwright.Promise.await!(promise)value = Playwright.Page.expect_event!(page, event, fn -> Playwright.Locator.click!(button) end)@spec wait_for_function(t(), String.t(), term() | nil, wait_for_function_options()) :: {:ok, Playwright.JSHandle.t()} | {:error, Playwright.error()}
Returns when the expression returns a truthy value. It returns a JSHandle of the truthy value.
Usage
The Playwright.Page.wait_for_function/4 can be used to observe viewport size change:
# Or Playwright.chromium/1 or Playwright.firefox/1.
browser = Playwright.webkit(playwright) |> BrowserType.launch!()
page = Browser.new_page!(browser)
watch_dog = Task.async(fn -> Page.wait_for_function!(page, "() => window.innerWidth < 100") end)
Page.set_viewport_size!(page, %{width: 50, height: 50})
Task.await(watch_dog)
Browser.close!(browser)To pass an argument to the predicate of Playwright.Page.wait_for_function/4 function:
selector = ".foo"
Page.wait_for_function!(page, "selector => !!document.querySelector(selector)", selector)Since Playwright 1.8.
Arguments
expression- Function to be evaluated in the page context.arg- Optional argument to pass toexpression.
Options
:polling(number/0|:raf) - If:pollingis:raf, thenexpressionis constantly executed inrequestAnimationFramecallback. If:pollingis a number, then it is treated as an interval in milliseconds at which the function would be executed. Defaults to:raf.:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. Allows to cancel the operation using anAbortSignal. If the signal is aborted, the operation will be aborted and fail. Note that providing a signal does not disable the default timeout, which can be changed usingPlaywright.BrowserContext.set_default_timeout/2orPlaywright.Page.set_default_timeout/2; passtimeout: 0to disable the timeout entirely.In Elixir, a
Playwright.AbortSignal(Playwright.AbortController.signal/1).:timeout(number/0|:infinity) - Maximum time to wait for in milliseconds. Defaults to30000(30 seconds). Pass0to disable timeout. The default value can be changed by using thePlaywright.BrowserContext.set_default_timeout/2orPlaywright.Page.set_default_timeout/2methods.In Elixir,
:infinityis the same as0: no timeout.
@spec wait_for_function!(t(), String.t(), term() | nil, wait_for_function_options()) :: Playwright.JSHandle.t()
Like wait_for_function/4, but returns the value and raises on error.
@spec wait_for_load_state( t(), :load | :domcontentloaded | :networkidle | nil, wait_for_load_state_options() ) :: :ok | {:error, Playwright.error()}
Returns when the required load state has been reached.
This resolves when the page 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.
Note
Most of the time, this method is not needed because Playwright auto-waits before every action.
Usage
# Click triggers navigation.
Page.get_by_role(page, :button) |> Locator.click!()
# Returns after the "load" event.
Page.wait_for_load_state!(page)popup_promise = Page.wait_for_event(page, :popup)
# Click triggers a popup.
Page.get_by_role(page, :button) |> Locator.click!()
popup = Promise.await!(popup_promise)
# Wait for the "DOMContentLoaded" event.
Page.wait_for_load_state!(popup, :domcontentloaded)
# Popup is ready to use.
IO.puts(Page.title!(popup))Since Playwright 1.8.
Arguments
state- 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 theloadevent to be fired.:domcontentloaded- wait for theDOMContentLoadedevent to be fired.:networkidle- DISCOURAGED wait until there are no network connections for at least500ms. Don't use this method for testing, rely on web assertions to assess readiness instead.
Options
The options may take the place of state, which is then nil.
:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. Allows to cancel the waiting using anAbortSignal. If the signal is aborted, the waiting will be aborted and the operation will fail. Note that providing a signal does not disable the default timeout, which can be changed usingPlaywright.BrowserContext.set_default_timeout/2; passtimeout: 0to disable the timeout entirely.In Elixir, a
Playwright.AbortSignal(Playwright.AbortController.signal/1).:timeout(number/0|:infinity) - Maximum operation time in milliseconds, defaults to 30 seconds, pass0to disable timeout. The default value can be changed by using thePlaywright.BrowserContext.set_default_navigation_timeout/2,Playwright.BrowserContext.set_default_timeout/2,Playwright.Page.set_default_navigation_timeout/2orPlaywright.Page.set_default_timeout/2methods.In Elixir,
:infinityis the same as0: no timeout.
@spec wait_for_load_state!( t(), :load | :domcontentloaded | :networkidle | nil, wait_for_load_state_options() ) :: :ok
Like wait_for_load_state/3, but returns the value and raises on error.
@spec wait_for_request( t(), String.t() | Regex.t() | Playwright.RegExp.t() | (Playwright.Request.t() -> boolean()), wait_for_request_options() ) :: Playwright.Promise.t()
Waits for the matching request and returns it. See waiting for event for more details about events.
Usage
# Start waiting for request before clicking: a promise, awaited after.
request_promise = Page.wait_for_request(page, "https://example.com/resource")
Page.get_by_text(page, "trigger request") |> Locator.click!()
first_request = Promise.await!(request_promise)
# Alternative way with a predicate.
request_promise =
Page.wait_for_request(page, fn request ->
Request.url(request) == "https://example.com/" and Request.method(request) == "GET"
end)
Page.get_by_text(page, "trigger request") |> Locator.click!()
second_request = Promise.await!(request_promise)Since Playwright 1.8.
Arguments
url_or_predicate- Request URL string, regex or predicate receivingRequestobject. When a:base_urlvia the context options was provided and the passed URL is a path, it gets merged via thenew URL()constructor.
Options
:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. Allows to cancel the waiting using anAbortSignal. If the signal is aborted, the waiting will be aborted and the operation will fail. Note that providing a signal does not disable the default timeout, which can be changed usingPlaywright.BrowserContext.set_default_timeout/2; passtimeout: 0to disable the timeout entirely.In Elixir, a
Playwright.AbortSignal(Playwright.AbortController.signal/1).:timeout(number/0|:infinity) - Maximum wait time in milliseconds, defaults to 30 seconds, pass0to disable the timeout. The default value can be changed by using thePlaywright.Page.set_default_timeout/2method.In Elixir,
:infinityis the same as0: no timeout.
Returns a Playwright.Promise at once, with the wait already set up. Start it before the action that triggers it and await it after with Playwright.Promise.await/1:
promise = Playwright.Page.wait_for_request(page, url_or_predicate)
Playwright.Locator.click!(button)
request = Playwright.Promise.await!(promise)The callback form expect_request/4 runs the action:
request = Playwright.Page.expect_request!(page, url_or_predicate, fn -> Playwright.Locator.click!(button) end)
@spec wait_for_request!( t(), String.t() | Regex.t() | Playwright.RegExp.t() | (Playwright.Request.t() -> boolean()), wait_for_request_options() ) :: Playwright.Request.t()
Like wait_for_request/3, but awaits the promise: Playwright.Promise.await!(wait_for_request(...)), the value or a raise.
Start waiting before the action
This waits from the time it is called, so it misses what the code before it triggered. Start the wait with wait_for_request/3 before the action and await it after, or use the callback form expect_request!/4:
promise = Playwright.Page.wait_for_request(page, url_or_predicate)
Playwright.Locator.click!(button)
request = Playwright.Promise.await!(promise)request = Playwright.Page.expect_request!(page, url_or_predicate, fn -> Playwright.Locator.click!(button) end)@spec wait_for_response( t(), String.t() | Regex.t() | Playwright.RegExp.t() | (Playwright.Response.t() -> boolean()), wait_for_response_options() ) :: Playwright.Promise.t()
Returns the matched response. See waiting for event for more details about events.
Usage
# Start waiting for response before clicking: a promise, awaited after.
response_promise = Page.wait_for_response(page, "https://example.com/resource")
Page.get_by_text(page, "trigger response") |> Locator.click!()
first_response = Promise.await!(response_promise)
# Alternative way with a predicate.
response_promise =
Page.wait_for_response(page, fn response ->
Response.url(response) == "https://example.com/" and Response.status(response) == 200 and
Request.method(Response.request(response)) == "GET"
end)
Page.get_by_text(page, "trigger response") |> Locator.click!()
second_response = Promise.await!(response_promise)Since Playwright 1.8.
Arguments
url_or_predicate- Request URL string, regex or predicate receivingResponseobject. When a:base_urlvia the context options was provided and the passed URL is a path, it gets merged via thenew URL()constructor.
Options
:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. Allows to cancel the waiting using anAbortSignal. If the signal is aborted, the waiting will be aborted and the operation will fail. Note that providing a signal does not disable the default timeout, which can be changed usingPlaywright.BrowserContext.set_default_timeout/2; passtimeout: 0to disable the timeout entirely.In Elixir, a
Playwright.AbortSignal(Playwright.AbortController.signal/1).:timeout(number/0|:infinity) - Maximum wait time in milliseconds, defaults to 30 seconds, pass0to disable the timeout. The default value can be changed by using thePlaywright.BrowserContext.set_default_timeout/2orPlaywright.Page.set_default_timeout/2methods.In Elixir,
:infinityis the same as0: no timeout.
Returns a Playwright.Promise at once, with the wait already set up. Start it before the action that triggers it and await it after with Playwright.Promise.await/1:
promise = Playwright.Page.wait_for_response(page, url_or_predicate)
Playwright.Locator.click!(button)
response = Playwright.Promise.await!(promise)The callback form expect_response/4 runs the action:
response = Playwright.Page.expect_response!(page, url_or_predicate, fn -> Playwright.Locator.click!(button) end)
@spec wait_for_response!( t(), String.t() | Regex.t() | Playwright.RegExp.t() | (Playwright.Response.t() -> boolean()), wait_for_response_options() ) :: Playwright.Response.t()
Like wait_for_response/3, but awaits the promise: Playwright.Promise.await!(wait_for_response(...)), the value or a raise.
Start waiting before the action
This waits from the time it is called, so it misses what the code before it triggered. Start the wait with wait_for_response/3 before the action and await it after, or use the callback form expect_response!/4:
promise = Playwright.Page.wait_for_response(page, url_or_predicate)
Playwright.Locator.click!(button)
response = Playwright.Promise.await!(promise)response = Playwright.Page.expect_response!(page, url_or_predicate, fn -> Playwright.Locator.click!(button) end)@spec wait_for_selector(t(), String.t(), wait_for_selector_options()) :: {:ok, nil | Playwright.ElementHandle.t()} | {:error, Playwright.error()}
Returns when element specified by selector satisfies :state option. Returns nil if waiting for hidden or
detached.
Note
Playwright automatically waits for element to be ready before performing an action. Using
Locator objects and web-first assertions makes the code wait-for-selector-free.
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 fail.
Usage
This method works across navigations:
# Or Playwright.firefox/1 or Playwright.webkit/1.
browser = Playwright.chromium(playwright) |> BrowserType.launch!()
page = Browser.new_page!(browser)
for current_url <- ["https://google.com", "https://bbc.com"] do
Page.goto!(page, current_url)
element = Page.wait_for_selector!(page, "img")
IO.puts("Loaded image: " <> ElementHandle.get_attribute!(element, "src"))
end
Browser.close!(browser)Discouraged
Use web assertions that assert visibility or a locator-based Playwright.Locator.wait_for/2 instead.
Read more about locators.
Since Playwright 1.8.
Arguments
selector- A selector to query for.
Options
:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. Allows to cancel the operation using anAbortSignal. If the signal is aborted, the operation will be aborted and fail. Note that providing a signal does not disable the default timeout, which can be changed usingPlaywright.BrowserContext.set_default_timeout/2orPlaywright.Page.set_default_timeout/2; passtimeout: 0to disable the timeout entirely.In Elixir, a
Playwright.AbortSignal(Playwright.AbortController.signal/1).:state(:attached|:detached|:visible|:hidden) - Defaults to:visible. Can be either::attached- wait for element to be present in DOM.:detached- wait for element to not be present in DOM.:visible- wait for element to have non-empty bounding box and novisibility:hidden. Note that element without any content or withdisplay:nonehas an empty bounding box and is not considered visible.:hidden- wait for element to be either detached from DOM, or have an empty bounding box orvisibility:hidden. This is opposite to the:visibleoption.
:strict(boolean/0) - Since Playwright 1.14. When true, the call requires selector to resolve to a single element. If given selector resolves to more than one element, the call fails.:timeout(number/0|:infinity) - Maximum time in milliseconds. Defaults to30000(30 seconds). Pass0to disable timeout. The default value can be changed by using thePlaywright.BrowserContext.set_default_timeout/2orPlaywright.Page.set_default_timeout/2methods.In Elixir,
:infinityis the same as0: no timeout.
@spec wait_for_selector!(t(), String.t(), wait_for_selector_options()) :: nil | Playwright.ElementHandle.t()
Like wait_for_selector/3, but returns the value and raises on error.
@spec wait_for_timeout(t(), number()) :: :ok | {:error, Playwright.error()}
Waits for the given timeout in milliseconds. It rejects :infinity.
Note that Playwright.Page.wait_for_timeout/2 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.
Usage
# wait for 1 second
Page.wait_for_timeout!(page, 1000)Discouraged
Never wait for timeout in production. Tests that wait for time are
inherently flaky. Use Locator actions and web assertions that wait automatically.
Since Playwright 1.8.
Arguments
timeout- A timeout to wait for
Like wait_for_timeout/2, but returns the value and raises on error.
@spec wait_for_url( t(), String.t() | Regex.t() | Playwright.RegExp.t() | (URI.t() -> boolean()), wait_for_url_options() ) :: :ok | {:error, Playwright.error()}
Waits for the main frame to navigate to the given URL.
Usage
# Clicking the link will indirectly cause a navigation
Page.click!(page, "a.delayed-navigation")
Page.wait_for_url!(page, "**/target.html")Since Playwright 1.11.
Arguments
url- A glob pattern, regex pattern, URL pattern, or predicate receivingURIto 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
:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. Allows to cancel the waiting using anAbortSignal. If the signal is aborted, the waiting will be aborted and the operation will fail. Note that providing a signal does not disable the default timeout, which can be changed usingPlaywright.BrowserContext.set_default_timeout/2; passtimeout: 0to disable the timeout entirely.In Elixir, a
Playwright.AbortSignal(Playwright.AbortController.signal/1).:timeout(number/0|:infinity) - Maximum operation time in milliseconds, defaults to 30 seconds, pass0to disable timeout. The default value can be changed by using thePlaywright.BrowserContext.set_default_navigation_timeout/2,Playwright.BrowserContext.set_default_timeout/2,Playwright.Page.set_default_navigation_timeout/2orPlaywright.Page.set_default_timeout/2methods.In Elixir,
:infinityis the same as0: no timeout.:wait_until(:load|:domcontentloaded|:networkidle|:commit) - When to consider operation succeeded, defaults to:load. Events can be either::domcontentloaded- consider operation to be finished when theDOMContentLoadedevent is fired.:load- consider operation to be finished when theloadevent is fired.:networkidle- DISCOURAGED consider operation to be finished when there are no network connections for at least500ms. Don't use this method for testing, rely on web assertions to assess readiness instead.:commit- consider operation to be finished when network response is received and the document started loading.
@spec wait_for_url!( t(), String.t() | Regex.t() | Playwright.RegExp.t() | (URI.t() -> boolean()), wait_for_url_options() ) :: :ok
Like wait_for_url/3, but returns the value and raises on error.
@spec webmcp(t()) :: Playwright.WebMCP.t()
Tools that the main frame registers through the experimental WebMCP browser API. Shortcut for Playwright.Frame.webmcp/1 of Playwright.Page.main_frame/1, see WebMCP for details.
Usage
tools = Page.webmcp(page) |> WebMCP.tools!()
result = Page.webmcp(page) |> WebMCP.call_tool!("add", %{a: 2, b: 40})Since Playwright 1.64.
@spec workers(t()) :: [Playwright.Worker.t()]
This method returns all of the dedicated WebWorkers associated with the page.
Note
This does not contain ServiceWorkers
Since Playwright 1.8.
Events
@spec add_listener(t(), :close, (t() -> term())) :: t()
@spec add_listener(t(), :console, (Playwright.ConsoleMessage.t() -> term())) :: t()
@spec add_listener(t(), :crash, (t() -> term())) :: t()
@spec add_listener(t(), :dialog, (Playwright.Dialog.t() -> term())) :: t()
@spec add_listener(t(), :dialog_closed, (Playwright.Dialog.t() -> term())) :: t()
@spec add_listener(t(), :dom_content_loaded, (t() -> term())) :: t()
@spec add_listener(t(), :download, (Playwright.Download.t() -> term())) :: t()
@spec add_listener(t(), :file_chooser, (Playwright.FileChooser.t() -> term())) :: t()
@spec add_listener(t(), :frame_attached, (Playwright.Frame.t() -> term())) :: t()
@spec add_listener(t(), :frame_detached, (Playwright.Frame.t() -> term())) :: t()
@spec add_listener(t(), :frame_navigated, (Playwright.Frame.t() -> term())) :: t()
@spec add_listener(t(), :load, (t() -> term())) :: t()
@spec add_listener(t(), :page_error, (Exception.t() -> term())) :: t()
@spec add_listener(t(), :popup, (t() -> term())) :: t()
@spec add_listener(t(), :request, (Playwright.Request.t() -> term())) :: t()
@spec add_listener(t(), :request_failed, (Playwright.Request.t() -> term())) :: t()
@spec add_listener(t(), :request_finished, (Playwright.Request.t() -> term())) :: t()
@spec add_listener(t(), :response, (Playwright.Response.t() -> term())) :: t()
@spec add_listener(t(), :web_socket, (Playwright.WebSocket.t() -> term())) :: t()
@spec add_listener(t(), :worker, (Playwright.Worker.t() -> term())) :: t()
@spec add_listener(t(), String.t(), (term() -> term())) :: t()
Adds an event listener for event, see the module docs for the events.
@spec off(t(), :close, (t() -> term())) :: t()
@spec off(t(), :console, (Playwright.ConsoleMessage.t() -> term())) :: t()
@spec off(t(), :crash, (t() -> term())) :: t()
@spec off(t(), :dialog, (Playwright.Dialog.t() -> term())) :: t()
@spec off(t(), :dialog_closed, (Playwright.Dialog.t() -> term())) :: t()
@spec off(t(), :dom_content_loaded, (t() -> term())) :: t()
@spec off(t(), :download, (Playwright.Download.t() -> term())) :: t()
@spec off(t(), :file_chooser, (Playwright.FileChooser.t() -> term())) :: t()
@spec off(t(), :frame_attached, (Playwright.Frame.t() -> term())) :: t()
@spec off(t(), :frame_detached, (Playwright.Frame.t() -> term())) :: t()
@spec off(t(), :frame_navigated, (Playwright.Frame.t() -> term())) :: t()
@spec off(t(), :load, (t() -> term())) :: t()
@spec off(t(), :page_error, (Exception.t() -> term())) :: t()
@spec off(t(), :popup, (t() -> term())) :: t()
@spec off(t(), :request, (Playwright.Request.t() -> term())) :: t()
@spec off(t(), :request_failed, (Playwright.Request.t() -> term())) :: t()
@spec off(t(), :request_finished, (Playwright.Request.t() -> term())) :: t()
@spec off(t(), :response, (Playwright.Response.t() -> term())) :: t()
@spec off(t(), :web_socket, (Playwright.WebSocket.t() -> term())) :: t()
@spec off(t(), :worker, (Playwright.Worker.t() -> term())) :: t()
@spec off(t(), String.t(), (term() -> term())) :: t()
Removes an event listener added by on/3 or add_listener/3.
@spec on(t(), :close, (t() -> term())) :: t()
@spec on(t(), :console, (Playwright.ConsoleMessage.t() -> term())) :: t()
@spec on(t(), :crash, (t() -> term())) :: t()
@spec on(t(), :dialog, (Playwright.Dialog.t() -> term())) :: t()
@spec on(t(), :dialog_closed, (Playwright.Dialog.t() -> term())) :: t()
@spec on(t(), :dom_content_loaded, (t() -> term())) :: t()
@spec on(t(), :download, (Playwright.Download.t() -> term())) :: t()
@spec on(t(), :file_chooser, (Playwright.FileChooser.t() -> term())) :: t()
@spec on(t(), :frame_attached, (Playwright.Frame.t() -> term())) :: t()
@spec on(t(), :frame_detached, (Playwright.Frame.t() -> term())) :: t()
@spec on(t(), :frame_navigated, (Playwright.Frame.t() -> term())) :: t()
@spec on(t(), :load, (t() -> term())) :: t()
@spec on(t(), :page_error, (Exception.t() -> term())) :: t()
@spec on(t(), :popup, (t() -> term())) :: t()
@spec on(t(), :request, (Playwright.Request.t() -> term())) :: t()
@spec on(t(), :request_failed, (Playwright.Request.t() -> term())) :: t()
@spec on(t(), :request_finished, (Playwright.Request.t() -> term())) :: t()
@spec on(t(), :response, (Playwright.Response.t() -> term())) :: t()
@spec on(t(), :web_socket, (Playwright.WebSocket.t() -> term())) :: t()
@spec on(t(), :worker, (Playwright.Worker.t() -> term())) :: t()
@spec on(t(), String.t(), (term() -> term())) :: t()
Adds an event listener for event, see the module docs for the events.
@spec once(t(), :close, (t() -> term())) :: t()
@spec once(t(), :console, (Playwright.ConsoleMessage.t() -> term())) :: t()
@spec once(t(), :crash, (t() -> term())) :: t()
@spec once(t(), :dialog, (Playwright.Dialog.t() -> term())) :: t()
@spec once(t(), :dialog_closed, (Playwright.Dialog.t() -> term())) :: t()
@spec once(t(), :dom_content_loaded, (t() -> term())) :: t()
@spec once(t(), :download, (Playwright.Download.t() -> term())) :: t()
@spec once(t(), :file_chooser, (Playwright.FileChooser.t() -> term())) :: t()
@spec once(t(), :frame_attached, (Playwright.Frame.t() -> term())) :: t()
@spec once(t(), :frame_detached, (Playwright.Frame.t() -> term())) :: t()
@spec once(t(), :frame_navigated, (Playwright.Frame.t() -> term())) :: t()
@spec once(t(), :load, (t() -> term())) :: t()
@spec once(t(), :page_error, (Exception.t() -> term())) :: t()
@spec once(t(), :popup, (t() -> term())) :: t()
@spec once(t(), :request, (Playwright.Request.t() -> term())) :: t()
@spec once(t(), :request_failed, (Playwright.Request.t() -> term())) :: t()
@spec once(t(), :request_finished, (Playwright.Request.t() -> term())) :: t()
@spec once(t(), :response, (Playwright.Response.t() -> term())) :: t()
@spec once(t(), :web_socket, (Playwright.WebSocket.t() -> term())) :: t()
@spec once(t(), :worker, (Playwright.Worker.t() -> term())) :: t()
@spec once(t(), String.t(), (term() -> term())) :: t()
Adds an event listener that is removed after it is triggered once. See on/3.
@spec prepend_listener(t(), :close, (t() -> term())) :: t()
@spec prepend_listener(t(), :console, (Playwright.ConsoleMessage.t() -> term())) :: t()
@spec prepend_listener(t(), :crash, (t() -> term())) :: t()
@spec prepend_listener(t(), :dialog, (Playwright.Dialog.t() -> term())) :: t()
@spec prepend_listener(t(), :dialog_closed, (Playwright.Dialog.t() -> term())) :: t()
@spec prepend_listener(t(), :dom_content_loaded, (t() -> term())) :: t()
@spec prepend_listener(t(), :download, (Playwright.Download.t() -> term())) :: t()
@spec prepend_listener(t(), :file_chooser, (Playwright.FileChooser.t() -> term())) :: t()
@spec prepend_listener(t(), :frame_attached, (Playwright.Frame.t() -> term())) :: t()
@spec prepend_listener(t(), :frame_detached, (Playwright.Frame.t() -> term())) :: t()
@spec prepend_listener(t(), :frame_navigated, (Playwright.Frame.t() -> term())) :: t()
@spec prepend_listener(t(), :load, (t() -> term())) :: t()
@spec prepend_listener(t(), :page_error, (Exception.t() -> term())) :: t()
@spec prepend_listener(t(), :popup, (t() -> term())) :: t()
@spec prepend_listener(t(), :request, (Playwright.Request.t() -> term())) :: t()
@spec prepend_listener(t(), :request_failed, (Playwright.Request.t() -> term())) :: t()
@spec prepend_listener(t(), :request_finished, (Playwright.Request.t() -> term())) :: t()
@spec prepend_listener(t(), :response, (Playwright.Response.t() -> term())) :: t()
@spec prepend_listener(t(), :web_socket, (Playwright.WebSocket.t() -> term())) :: t()
@spec prepend_listener(t(), :worker, (Playwright.Worker.t() -> term())) :: t()
@spec prepend_listener(t(), String.t(), (term() -> term())) :: t()
Adds an event listener for event, see the module docs for the events.
@spec remove_listener(t(), :close, (t() -> term())) :: t()
@spec remove_listener(t(), :console, (Playwright.ConsoleMessage.t() -> term())) :: t()
@spec remove_listener(t(), :crash, (t() -> term())) :: t()
@spec remove_listener(t(), :dialog, (Playwright.Dialog.t() -> term())) :: t()
@spec remove_listener(t(), :dialog_closed, (Playwright.Dialog.t() -> term())) :: t()
@spec remove_listener(t(), :dom_content_loaded, (t() -> term())) :: t()
@spec remove_listener(t(), :download, (Playwright.Download.t() -> term())) :: t()
@spec remove_listener(t(), :file_chooser, (Playwright.FileChooser.t() -> term())) :: t()
@spec remove_listener(t(), :frame_attached, (Playwright.Frame.t() -> term())) :: t()
@spec remove_listener(t(), :frame_detached, (Playwright.Frame.t() -> term())) :: t()
@spec remove_listener(t(), :frame_navigated, (Playwright.Frame.t() -> term())) :: t()
@spec remove_listener(t(), :load, (t() -> term())) :: t()
@spec remove_listener(t(), :page_error, (Exception.t() -> term())) :: t()
@spec remove_listener(t(), :popup, (t() -> term())) :: t()
@spec remove_listener(t(), :request, (Playwright.Request.t() -> term())) :: t()
@spec remove_listener(t(), :request_failed, (Playwright.Request.t() -> term())) :: t()
@spec remove_listener(t(), :request_finished, (Playwright.Request.t() -> term())) :: t()
@spec remove_listener(t(), :response, (Playwright.Response.t() -> term())) :: t()
@spec remove_listener(t(), :web_socket, (Playwright.WebSocket.t() -> term())) :: t()
@spec remove_listener(t(), :worker, (Playwright.Worker.t() -> term())) :: t()
@spec remove_listener(t(), String.t(), (term() -> term())) :: t()
Removes an event listener added by on/3 or add_listener/3.