Page operations - navigation, content, evaluation, screenshots.
The Page class is the central API surface of Playwright. Wraps all Page methods with idiomatic Clojure functions.
Page operations - navigation, content, evaluation, screenshots. The Page class is the central API surface of Playwright. Wraps all Page methods with idiomatic Clojure functions.
(add-script-tag page opts)Adds a script tag to the page.
Params:
page - Page instance.
opts - Map with :url, :path, or :content.
Returns: ElementHandle or anomaly map.
Adds a script tag to the page. Params: `page` - Page instance. `opts` - Map with :url, :path, or :content. Returns: ElementHandle or anomaly map.
(add-style-tag page opts)Adds a style tag to the page.
Params:
page - Page instance.
opts - Map with :url, :path, or :content.
Returns: ElementHandle or anomaly map.
Adds a style tag to the page. Params: `page` - Page instance. `opts` - Map with :url, :path, or :content. Returns: ElementHandle or anomaly map.
(bring-to-front page)Brings page to front (activates tab).
Params:
page - Page instance.
Brings page to front (activates tab). Params: `page` - Page instance.
(content page)Returns the full HTML content of the page.
Params:
page - Page instance.
Returns: String. HTML content.
Returns the full HTML content of the page. Params: `page` - Page instance. Returns: String. HTML content.
(emulate-media! page media-opts)Emulates media type and features.
Params:
page - Page instance.
opts - Map. Emulate media options.
Emulates media type and features. Params: `page` - Page instance. `opts` - Map. Emulate media options.
(evaluate page expression)(evaluate page expression arg)Evaluates JavaScript expression in the page context.
Params:
page - Page instance.
expression - String. JavaScript expression.
arg - Optional. Argument to pass to the expression.
Returns: Result of JavaScript evaluation or anomaly map on failure.
Evaluates JavaScript expression in the page context. Params: `page` - Page instance. `expression` - String. JavaScript expression. `arg` - Optional. Argument to pass to the expression. Returns: Result of JavaScript evaluation or anomaly map on failure.
(evaluate-handle page expression)(evaluate-handle page expression arg)Like evaluate, but returns a JSHandle.
Params:
page - Page instance.
expression - String. JavaScript expression.
arg - Optional. Argument.
Returns: JSHandle or anomaly map.
Like evaluate, but returns a JSHandle. Params: `page` - Page instance. `expression` - String. JavaScript expression. `arg` - Optional. Argument. Returns: JSHandle or anomaly map.
(expose-binding! page name f)Exposes a Clojure function as a binding.
Params:
page - Page instance.
name - String. Binding name.
fn - Function. The binding function.
Exposes a Clojure function as a binding. Params: `page` - Page instance. `name` - String. Binding name. `fn` - Function. The binding function.
(expose-function! page name f)Exposes a Clojure function to JavaScript.
Params:
page - Page instance.
name - String. Function name in JavaScript.
fn - Function. The Clojure function to expose.
Exposes a Clojure function to JavaScript. Params: `page` - Page instance. `name` - String. Function name in JavaScript. `fn` - Function. The Clojure function to expose.
(frame-by-name page name)Returns a frame by its name attribute.
Params:
page - Page instance.
name - String. Frame name.
Returns: Frame or nil.
Returns a frame by its name attribute. Params: `page` - Page instance. `name` - String. Frame name. Returns: Frame or nil.
(frame-by-url page pattern)Returns a frame by matching URL pattern.
Params:
page - Page instance.
pattern - String glob, regex Pattern, or predicate.
Returns: Frame or nil.
Returns a frame by matching URL pattern. Params: `page` - Page instance. `pattern` - String glob, regex Pattern, or predicate. Returns: Frame or nil.
(frames page)Returns all frames in the page.
Params:
page - Page instance.
Returns: Vector of Frame instances.
Returns all frames in the page. Params: `page` - Page instance. Returns: Vector of Frame instances.
(get-by-alt-text page text)Locates elements by alt text.
Params:
page - Page instance.
text - String or Pattern.
Returns: Locator instance.
Locates elements by alt text. Params: `page` - Page instance. `text` - String or Pattern. Returns: Locator instance.
(get-by-label page text)Locates elements by their label text.
Params:
page - Page instance.
text - String or Pattern.
Returns: Locator instance.
Locates elements by their label text. Params: `page` - Page instance. `text` - String or Pattern. Returns: Locator instance.
(get-by-placeholder page text)Locates elements by placeholder text.
Params:
page - Page instance.
text - String or Pattern.
Returns: Locator instance.
Locates elements by placeholder text. Params: `page` - Page instance. `text` - String or Pattern. Returns: Locator instance.
(get-by-role page role)(get-by-role page role opts)Locates elements by their ARIA role.
Params:
page - Page instance.
role - AriaRole enum value.
opts - Map, optional. GetByRoleOptions:
:name - String or Pattern. Accessible name to match.
:exact - Boolean. Exact match for name.
:checked - Boolean. Match checked state.
:disabled - Boolean. Match disabled state.
:expanded - Boolean. Match expanded state.
:include-hidden - Boolean. Include hidden elements.
:level - Integer. Heading level.
:pressed - Boolean. Match pressed state.
:selected - Boolean. Match selected state.
Returns: Locator instance.
Locates elements by their ARIA role.
Params:
`page` - Page instance.
`role` - AriaRole enum value.
`opts` - Map, optional. GetByRoleOptions:
:name - String or Pattern. Accessible name to match.
:exact - Boolean. Exact match for name.
:checked - Boolean. Match checked state.
:disabled - Boolean. Match disabled state.
:expanded - Boolean. Match expanded state.
:include-hidden - Boolean. Include hidden elements.
:level - Integer. Heading level.
:pressed - Boolean. Match pressed state.
:selected - Boolean. Match selected state.
Returns:
Locator instance.(get-by-test-id page test-id)Locates elements by test ID attribute.
Params:
page - Page instance.
test-id - String or Pattern.
Returns: Locator instance.
Locates elements by test ID attribute. Params: `page` - Page instance. `test-id` - String or Pattern. Returns: Locator instance.
(get-by-text page text)Locates elements by their text content.
Params:
page - Page instance.
text - String or Pattern.
Returns: Locator instance.
Locates elements by their text content. Params: `page` - Page instance. `text` - String or Pattern. Returns: Locator instance.
(get-by-title page text)Locates elements by title attribute.
Params:
page - Page instance.
text - String or Pattern.
Returns: Locator instance.
Locates elements by title attribute. Params: `page` - Page instance. `text` - String or Pattern. Returns: Locator instance.
(go-back page)(go-back page nav-opts)Navigates back in history.
Params:
page - Page instance.
opts - Map, optional. Navigation options.
Returns: Response or nil, or anomaly map on failure.
Navigates back in history. Params: `page` - Page instance. `opts` - Map, optional. Navigation options. Returns: Response or nil, or anomaly map on failure.
(go-forward page)(go-forward page nav-opts)Navigates forward in history.
Params:
page - Page instance.
opts - Map, optional. Navigation options.
Returns: Response or nil, or anomaly map on failure.
Navigates forward in history. Params: `page` - Page instance. `opts` - Map, optional. Navigation options. Returns: Response or nil, or anomaly map on failure.
(is-closed? page)Returns true if the page has been closed.
Params:
page - Page instance.
Returns: Boolean.
Returns true if the page has been closed. Params: `page` - Page instance. Returns: Boolean.
(locator page selector)Creates a Locator for finding elements on the page.
Params:
page - Page instance.
selector - String. CSS or text selector.
Returns: Locator instance.
Creates a Locator for finding elements on the page. Params: `page` - Page instance. `selector` - String. CSS or text selector. Returns: Locator instance.
(main-frame page)Returns the main frame of the page.
Params:
page - Page instance.
Returns: Frame instance.
Returns the main frame of the page. Params: `page` - Page instance. Returns: Frame instance.
(navigate page url)(navigate page url nav-opts)Navigates the page to a URL.
Params:
page - Page instance.
url - String. URL to navigate to.
opts - Map, optional. Navigation options.
Returns: Response or nil, or anomaly map on failure.
Navigates the page to a URL. Params: `page` - Page instance. `url` - String. URL to navigate to. `opts` - Map, optional. Navigation options. Returns: Response or nil, or anomaly map on failure.
(on-close page handler)Registers a handler for page close.
Params:
page - Page instance.
handler - Function called with the page when it closes.
Registers a handler for page close. Params: `page` - Page instance. `handler` - Function called with the page when it closes.
(on-console page handler)Registers a handler for console messages.
Params:
page - Page instance.
handler - Function that receives a ConsoleMessage.
Registers a handler for console messages. Params: `page` - Page instance. `handler` - Function that receives a ConsoleMessage.
(on-dialog page handler)Registers a handler for dialogs.
Params:
page - Page instance.
handler - Function that receives a Dialog.
Registers a handler for dialogs. Params: `page` - Page instance. `handler` - Function that receives a Dialog.
(on-download page handler)Registers a handler for downloads.
Params:
page - Page instance.
handler - Function that receives a Download.
Registers a handler for downloads. Params: `page` - Page instance. `handler` - Function that receives a Download.
(on-page-error page handler)Registers a handler for page errors.
Params:
page - Page instance.
handler - Function that receives an error string.
Registers a handler for page errors. Params: `page` - Page instance. `handler` - Function that receives an error string.
(on-popup page handler)Registers a handler for popup pages.
Params:
page - Page instance.
handler - Function that receives a Page.
Registers a handler for popup pages. Params: `page` - Page instance. `handler` - Function that receives a Page.
(on-request page handler)Registers a handler for requests.
Params:
page - Page instance.
handler - Function that receives a Request.
Registers a handler for requests. Params: `page` - Page instance. `handler` - Function that receives a Request.
(on-response page handler)Registers a handler for responses.
Params:
page - Page instance.
handler - Function that receives a Response.
Registers a handler for responses. Params: `page` - Page instance. `handler` - Function that receives a Response.
(once-dialog page handler)Registers a one-time handler for the next dialog. The handler is automatically removed after the first dialog is handled.
Params:
page - Page instance.
handler - Function that receives a Dialog.
Registers a one-time handler for the next dialog. The handler is automatically removed after the first dialog is handled. Params: `page` - Page instance. `handler` - Function that receives a Dialog.
(opener page)Returns the opener page, if any.
Params:
page - Page instance.
Returns: Page or nil.
Returns the opener page, if any. Params: `page` - Page instance. Returns: Page or nil.
(page-context page)Returns the BrowserContext that the page belongs to.
Params:
page - Page instance.
Returns: BrowserContext instance.
Returns the BrowserContext that the page belongs to. Params: `page` - Page instance. Returns: BrowserContext instance.
(page-keyboard page)Returns the Keyboard for this page.
Params:
page - Page instance.
Returns: Keyboard instance.
Returns the Keyboard for this page. Params: `page` - Page instance. Returns: Keyboard instance.
(page-mouse page)Returns the Mouse for this page.
Params:
page - Page instance.
Returns: Mouse instance.
Returns the Mouse for this page. Params: `page` - Page instance. Returns: Mouse instance.
(page-touchscreen page)Returns the Touchscreen for this page.
Params:
page - Page instance.
Returns: Touchscreen instance.
Returns the Touchscreen for this page. Params: `page` - Page instance. Returns: Touchscreen instance.
(pdf page)(pdf page pdf-opts)Generates a PDF of the page. Only works in Chromium headless.
Params:
page - Page instance.
opts - Map, optional. PDF options.
Returns: byte[] of the PDF data, or anomaly map on failure.
Generates a PDF of the page. Only works in Chromium headless. Params: `page` - Page instance. `opts` - Map, optional. PDF options. Returns: byte[] of the PDF data, or anomaly map on failure.
(reload page)(reload page nav-opts)Reloads the page.
Params:
page - Page instance.
opts - Map, optional. Reload options.
Returns: Response or nil, or anomaly map on failure.
Reloads the page. Params: `page` - Page instance. `opts` - Map, optional. Reload options. Returns: Response or nil, or anomaly map on failure.
(route! page pattern handler)Registers a route handler for URL pattern.
Params:
page - Page instance.
pattern - String glob or regex Pattern.
handler - Function that receives a Route.
Registers a route handler for URL pattern. Params: `page` - Page instance. `pattern` - String glob or regex Pattern. `handler` - Function that receives a Route.
(screenshot page)(screenshot page ss-opts)Takes a screenshot of the page.
Params:
page - Page instance.
opts - Map, optional. Screenshot options.
Returns: byte[] of the image data, or anomaly map on failure.
Takes a screenshot of the page. Params: `page` - Page instance. `opts` - Map, optional. Screenshot options. Returns: byte[] of the image data, or anomaly map on failure.
(set-content! page html)(set-content! page html set-opts)Sets the HTML content of the page.
Params:
page - Page instance.
html - String. HTML content.
opts - Map, optional. Options.
Sets the HTML content of the page. Params: `page` - Page instance. `html` - String. HTML content. `opts` - Map, optional. Options.
(set-default-navigation-timeout! page timeout)Sets the default navigation timeout.
Params:
page - Page instance.
timeout - Double. Timeout in milliseconds.
Sets the default navigation timeout. Params: `page` - Page instance. `timeout` - Double. Timeout in milliseconds.
(set-default-timeout! page timeout)Sets the default timeout for page operations.
Params:
page - Page instance.
timeout - Double. Timeout in milliseconds.
Sets the default timeout for page operations. Params: `page` - Page instance. `timeout` - Double. Timeout in milliseconds.
(set-extra-http-headers! page headers)Sets extra HTTP headers for all requests on this page.
Params:
page - Page instance.
headers - Map of string->string.
Sets extra HTTP headers for all requests on this page. Params: `page` - Page instance. `headers` - Map of string->string.
(set-viewport-size! page width height)Sets the viewport size.
Params:
page - Page instance.
width - Long. Width in pixels.
height - Long. Height in pixels.
Sets the viewport size. Params: `page` - Page instance. `width` - Long. Width in pixels. `height` - Long. Height in pixels.
(title page)Returns the page title.
Params:
page - Page instance.
Returns: String.
Returns the page title. Params: `page` - Page instance. Returns: String.
(unroute! page pattern)Removes a route handler.
Params:
page - Page instance.
pattern - String glob or regex Pattern.
Removes a route handler. Params: `page` - Page instance. `pattern` - String glob or regex Pattern.
(url page)Returns the current page URL.
Params:
page - Page instance.
Returns: String.
Returns the current page URL. Params: `page` - Page instance. Returns: String.
(video page)Returns the Video for this page, if recording.
Params:
page - Page instance.
Returns: Video or nil.
Returns the Video for this page, if recording. Params: `page` - Page instance. Returns: Video or nil.
(viewport-size page)Returns the viewport size of the page.
Params:
page - Page instance.
Returns: Map with :width and :height, or nil.
Returns the viewport size of the page. Params: `page` - Page instance. Returns: Map with :width and :height, or nil.
(wait-for-download page action)(wait-for-download page action opts)Waits for a download to start while executing action.
Params:
page - Page instance.
action - No-arg function that triggers the download.
opts - Optional map. {:predicate fn, :timeout ms}
Returns: Download or anomaly map on timeout.
Waits for a download to start while executing `action`.
Params:
`page` - Page instance.
`action` - No-arg function that triggers the download.
`opts` - Optional map. {:predicate fn, :timeout ms}
Returns:
Download or anomaly map on timeout.(wait-for-file-chooser page action)(wait-for-file-chooser page action opts)Waits for a file chooser dialog while executing action.
Params:
page - Page instance.
action - No-arg function that triggers the file chooser (e.g. clicking an input).
opts - Optional map. {:predicate fn, :timeout ms}
Returns: FileChooser or anomaly map on timeout.
Example: (let [fc (page/wait-for-file-chooser pg #(locator/click (page/locator pg "input[type=file]")))] (util/file-chooser-set-files! fc "/path/to/file.txt"))
Waits for a file chooser dialog while executing `action`.
Params:
`page` - Page instance.
`action` - No-arg function that triggers the file chooser (e.g. clicking an input).
`opts` - Optional map. {:predicate fn, :timeout ms}
Returns:
FileChooser or anomaly map on timeout.
Example:
(let [fc (page/wait-for-file-chooser pg
#(locator/click (page/locator pg "input[type=file]")))]
(util/file-chooser-set-files! fc "/path/to/file.txt"))(wait-for-function page expression)Waits for a JavaScript function to return a truthy value.
Params:
page - Page instance.
expression - String. JavaScript expression.
Returns: JSHandle or anomaly map on timeout.
Waits for a JavaScript function to return a truthy value. Params: `page` - Page instance. `expression` - String. JavaScript expression. Returns: JSHandle or anomaly map on timeout.
(wait-for-load-state page)(wait-for-load-state page state)Waits for the page to reach a load state.
Params:
page - Page instance.
state - Keyword, optional. :load :domcontentloaded :networkidle.
Returns: nil or anomaly map on timeout.
Waits for the page to reach a load state. Params: `page` - Page instance. `state` - Keyword, optional. :load :domcontentloaded :networkidle. Returns: nil or anomaly map on timeout.
(wait-for-popup page action)(wait-for-popup page action opts)Waits for a popup page to open while executing action.
Params:
page - Page instance.
action - No-arg function that triggers the popup.
opts - Optional map. {:predicate fn, :timeout ms}
Returns: Page (the popup) or anomaly map on timeout.
Waits for a popup page to open while executing `action`.
Params:
`page` - Page instance.
`action` - No-arg function that triggers the popup.
`opts` - Optional map. {:predicate fn, :timeout ms}
Returns:
Page (the popup) or anomaly map on timeout.(wait-for-response page url-or-fn callback)Waits for a response matching the URL or predicate.
Params:
page - Page instance.
url-or-fn - String or predicate fn.
callback - Runnable to trigger the response.
Returns: Response or anomaly map on timeout.
Waits for a response matching the URL or predicate. Params: `page` - Page instance. `url-or-fn` - String or predicate fn. `callback` - Runnable to trigger the response. Returns: Response or anomaly map on timeout.
(wait-for-selector page selector)(wait-for-selector page selector wait-opts)Waits for a selector to satisfy a condition.
Params:
page - Page instance.
selector - String. CSS selector.
opts - Map, optional. Wait options.
Returns: ElementHandle or nil, or anomaly map on timeout.
Waits for a selector to satisfy a condition. Params: `page` - Page instance. `selector` - String. CSS selector. `opts` - Map, optional. Wait options. Returns: ElementHandle or nil, or anomaly map on timeout.
(wait-for-timeout page timeout)Waits for the specified time in milliseconds.
Params:
page - Page instance.
timeout - Double. Time to wait in ms.
Waits for the specified time in milliseconds. Params: `page` - Page instance. `timeout` - Double. Time to wait in ms.
(wait-for-url page url)Waits for the page to navigate to a URL.
Params:
page - Page instance.
url - String glob, regex Pattern, or predicate.
Waits for the page to navigate to a URL. Params: `page` - Page instance. `url` - String glob, regex Pattern, or predicate.
(workers page)Returns all workers in the page.
Params:
page - Page instance.
Returns: Vector of Worker instances.
Returns all workers in the page. Params: `page` - Page instance. Returns: Vector of Worker instances.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |