Playwright.Page (playwright v0.1.16-preview-3) 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.

See Playwright.Frame.query_selector!/3.

Link to this section Types

Specs

function_or_options() :: (... -> any()) | options() | nil

Specs

options() :: map()

Specs

t() :: %Playwright.Page{
  connection: term(),
  guid: term(),
  is_closed: term(),
  listeners: term(),
  main_frame: term(),
  owned_context: term(),
  parent: term(),
  type: term(),
  viewport_size: term()
}

%Playwright.Page{}

Link to this section Functions

Link to this function

click(page, selector, options \\ %{})

View Source

See Playwright.Frame.click/3.

Link to this function

close(owner, options \\ %{})

View Source

Specs

close(t() | {:ok, t()}, options()) :: :ok

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 / nametypedescription
run_before_unloadoptionboolean()Whether to run the before unload page handlers. (default: false)

NOTE

if option: run_before_unload is passed as true, a :beforeunload dialog might be summoned and should be handled manually via Playwright.Page.on/3.

Specs

content(t() | {:ok, t()}) :: {:ok, binary()}

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.

Link to this function

eval_on_selector(owner, selector, expression, arg \\ nil, options \\ %{})

View Source

Specs

eval_on_selector(t(), binary(), binary(), term(), map()) :: term()
Link to this function

evaluate(page, expression, arg \\ nil)

View Source

See Playwright.Frame.evaluate/3.

Link to this function

evaluate_handle(page, expression, arg \\ nil)

View Source

See Playwright.Frame.evaluate_handle/3.

Link to this function

expect_event(owner, event, trigger)

View Source

See Playwright.BrowserContext.expect_event/3.

Link to this function

fill(page, selector, value)

View Source

See Playwright.Frame.fill/3.

Link to this function

get_attribute(page, selector, name, options \\ %{})

View Source

See Playwright.Frame.get_attribute/4.

Link to this function

goto(page, url, params \\ %{})

View Source

See Playwright.Frame.goto/3.

Link to this function

on(owner, event, callback)

View Source
Link to this function

press(page, selector, key, options \\ %{})

View Source

See Playwright.Frame.press/4.

Link to this function

q(page, selector, options \\ %{})

View Source

See Playwright.Frame.q/3.

Link to this function

q!(page, selector, options \\ %{})

View Source

See Playwright.Frame.q!/3.

Link to this function

qq(page, selector, options \\ %{})

View Source

See Playwright.Frame.qq/3.

Link to this function

query_selector(page, selector, options \\ %{})

View Source

See Playwright.Frame.query_selector/3.

Link to this function

query_selector!(page, selector, options \\ %{})

View Source

See Playwright.Frame.query_selector!/3.

Link to this function

query_selector_all(page, selector, options \\ %{})

View Source

See Playwright.Frame.query_selector_all/3.

Link to this function

route(owner, pattern, callback, options \\ %{})

View Source

Specs

route(t(), binary(), function(), map()) :: {atom(), t()}
Link to this function

screenshot(owner, options \\ %{})

View Source

Specs

screenshot(t(), map()) :: {:ok, binary()}
Link to this function

set_content(page, html, options \\ %{})

View Source

See Playwright.Frame.set_content/3.

Link to this function

text_content(page, selector, options \\ %{})

View Source

See Playwright.Frame.text_content/3.

See Playwright.Frame.title/1.

See Playwright.Frame.url/1.

Link to this function

wait_for_load_state(owner, state \\ "load", options \\ %{})

View Source

Specs

wait_for_load_state(t(), binary(), options()) :: {:ok, t()}
Link to this function

wait_for_selector(page, selector, options)

View Source

See Playwright.Frame.wait_for_selector/3.