Auto-waits for a match, then highlights the exact text inside it.
paparazzi finds the substring among the element's text nodes and sets
the page's real window selection, even when the match spans inline tags
such as <em> and <strong>. Typing afterwards replaces it – call
pz_act_type() with target = NULL, which inserts into whatever has
focus.
Arguments
- ctx
A paparazzi context.
- text
A string to select. Must appear exactly in the element, across tags if needed; not found is an error.
- ...
Checked empty; reserved for future use.
- target
A CSS selector string, a
pz_loc()spec, or a list of specs (a union matching any of them).NULLuses the current scope; at the root context a target is required.
Details
While recording with a visible cursor, paparazzi animates a drag across the text, then sets the exact selection with the browser's Range API. The drag sends real mouse-move events, which can trigger page hover effects such as tooltips or hover menus. Outside a recording, selection is instant and leaves the cursor where it was, without sending mouse-move events.
A contenteditable target is focused too (dragging across editable text focuses it, and that focus is where the typing lands); a static target is not.
Acting on the page
The pz_act_*() functions use the page the way a person would. They send
real browser input, such as pointer moves, clicks and key presses, or use
the browser's own focus and text-selection methods. They never set a form
value directly.
An action with a target looks for it in the current scope and waits until
it matches an element. Inside a scope, target = NULL acts on the scope's
element, and scrolling with by or to scrolls the scope's container. An
explicit target is scrolled into view first when needed. A few actions,
like pz_act_press(), take no target and act on the focused element
instead.
While the page is recording, actions are staged as pz_stage() sets them
up: the cursor glides to pointer targets, typing is paced, scrolls normally
use the mouse wheel, and the page holds for the staged pause afterward.
Without a recording, actions go straight to their final state.
To set a value directly instead, without staging, use pz_set_value(),
pz_set_files(), or pz_set_shiny_input().
Examples
page <- pz_open(pz_example("tasks"))
# Typing replaces the selection
page |>
pz_find(pz_loc(".task", has_text = "Renew passport")) |>
pz_act_click(".task-edit") |>
pz_find(".task-title") |>
pz_act_select_text("passport") |>
pz_act_type("driving licence") |>
pz_act_press("Enter") |>
pz_get_text()
#> [1] "Renew driving licence"
pz_close(page)
