Playwright.Page (playwright v0.1.17-preview-1) View Source
Page provides methods to interact with a single tab in a
Playwright.Browser, or an extension background page
in Chromium.
One Playwright.Browser instance might have multiple Page instances.
Example
Create a page, navigate it to a URL, and save a screenshot:
{:ok, page} = Browser.new_page(browser)
{:ok, resp} = Page.goto(page, "https://example.com")
{:ok _} = Page.screenshot(page, %{path: "screenshot.png"})
:ok = Page.close(page)The Page module is capable of hanlding various emitted events (described below).
Example
Log a message for a single page load event (WIP: once is not yet implemented):
Page.once(page, :load, fn e ->
IO.puts("page loaded!")
end)Unsubscribe from events with the remove_lstener function (WIP: remove_listener is not yet implemented):
def log_request(request) do
IO.inspect(label: "A request was made")
end
Page.on(page, :request, fn e ->
log_request(e.pages.request)
end)
Page.remove_listener(page, log_request)
Link to this section Summary
Functions
Closes the Page.
Get the full HTML contents of the page, including the doctype.
Get the Playwright.BrowserContext that the page belongs to.
A shortcut for the main frame's Playwright.Frame.dblclick/3.
A shortcut for the main frame's Playwright.Frame.dispatch_event/5.
A shortcut for the main frame's Playwright.Frame.focus/3.
A shortcut for the main frame's Playwright.Frame.hover/2.
Optional callback implementation for Playwright.ChannelOwner.init/2.
See Playwright.Frame.query_selector!/3.
A shortcut for the main frame's Playwright.Frame.select_option/4.
See Playwright.Frame.url/1.
Link to this section Types
Link to this section Functions
Specs
Closes the Page.
If the Page has an "owned context" (1-to-1 co-dependency with a
Playwright.BrowserContext), that context is closed as well.
If option: run_before_unload is false, does not run any unload handlers and
waits for the page to be closed. If option: run_before_unload is true
the function will run unload handlers, but will not wait for the page to
close. By default, Playwright.Page.close/1 does not run :beforeunload
handlers.
Returns
:ok
Arguments
| key / name | type | description | |
|---|---|---|---|
run_before_unload | option | boolean() | Whether to run the before unload page handlers. (default: false) |
NOTE
if
option: run_before_unloadis passed astrue, a:beforeunloaddialog might be summoned and should be handled manually viaPlaywright.Page.on/3.
Specs
Get the full HTML contents of the page, including the doctype.
Specs
context(t() | {:ok, t()}) :: Playwright.BrowserContext.t()
Get the Playwright.BrowserContext that the page belongs to.
Specs
A shortcut for the main frame's Playwright.Frame.dblclick/3.
dispatch_event(page, selector, type, event_init \\ nil, options \\ %{})
View SourceSpecs
dispatch_event( t(), binary(), atom() | binary(), Playwright.Frame.evaluation_argument(), options() ) :: :ok
A shortcut for the main frame's Playwright.Frame.dispatch_event/5.
eval_on_selector(owner, selector, expression, arg \\ nil, options \\ %{})
View SourceSpecs
Specs
A shortcut for the main frame's Playwright.Frame.focus/3.
A shortcut for the main frame's Playwright.Frame.hover/2.
Specs
Optional callback implementation for Playwright.ChannelOwner.init/2.
If implemented, the callback will receive:
- The newly created "channel owner" struct.
- The
:initializerreceived from the Playwright browser server.
The implementation has the option of "patching" the struct as stored in the catalog, and/or binding event handlers.
Example
def init(owner, _initializer) do
Channel.bind(owner, :close, fn event ->
Logger.warn("Closing #{inspect(event.target)}")
end)
{:ok, %{owner | version: "1.2.3"}}
endReturns
{:ok, %{}}
Arguments
| key / name | type | description | |
|---|---|---|---|
owner | param | struct() | The newly created channel owner (resource). |
initializer | param | struct() | The initializer received from with the channel owner instance was derived. |
Specs
locator(t(), binary()) :: Playwright.Locator.t()
See Playwright.Frame.q/3.
See Playwright.Frame.query_selector!/3.
Specs
Specs
Specs
A shortcut for the main frame's Playwright.Frame.select_option/4.
See Playwright.Frame.url/1.