With a target, auto-waits for the element to be actionable –
visible with a non-empty box and receiving pointer events at its center
(not covered by another element) – then scrolls it into view, clicks
the center of it (real mouse events, so the element genuinely gains
focus), and inserts text at the caret – the caret lands where the
click lands, just like a real user. With target = NULL at the
root context, inserts into whatever element currently has focus;
if nothing editable is focused, the text goes nowhere, exactly like
typing into a page with no focused field.
Insertion is instant (one insertText), except while recording
with typing = "natural" (the default; see pz_stage()): one
insertText per character with randomized delays around
typing_speed, so the video shows the text appearing. While
recording, paparazzi fades the cursor out during typing so it doesn't
cover the text. The next pointer action fades it back in. For
a value-setting primitive that works on selects, checkboxes, and range
inputs, see pz_set_value().
Arguments
- ctx
A paparazzi context.
- text
A string to type.
- ...
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 or, at the root context, the focused element.
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().
See also
pz_act_press() for key combos (Enter, Control+A, ...) and
pz_act_click().
Examples
page <- pz_open(pz_example("tasks"))
page |> pz_act_type("Buy milk", target = "#task-title")
pz_get_value(page, target = "#task-title")
#> [1] "Buy milk"
# Typing fires input events, so the page reacts: Add is now enabled
pz_expect_enabled(page, target = "#add-task")
# At the root, target = NULL types into the focused element
page |> pz_act_type(" and eggs")
pz_get_value(page, target = "#task-title")
#> [1] "Buy milk and eggs"
pz_close(page)
