Skip to contents

Polls expr until it evaluates truthy, then returns ctx invisibly. Each poll awaits a promise expr returns, so async conditions work; JavaScript truthiness applies (a non-empty string or a non-zero number counts). An expr that throws is a JavaScript error, not a failed poll.

Usage

pz_wait_for_js(ctx, expr, ..., timeout = NULL)

Arguments

ctx

A paparazzi context.

expr

A string of JavaScript that evaluates truthy when the condition holds. A returned promise is awaited first.

...

Checked empty; reserved for future use.

timeout

Seconds before giving up; NULL uses the session default.

Value

ctx, invisibly.

Details

There is deliberately no element-state wait (pz_wait_for(target, state =)): pz_expect_visible(), pz_expect_hidden(), and pz_expect_exists() with not = TRUE already retry, so they wait.

Examples

page <- pz_open(pz_example("tasks"))
page |>
  pz_act_type("Buy milk", target = "#task-title") |>
  pz_act_press("Enter") |>
  pz_wait_for_js("document.querySelectorAll('.task').length === 8")
pz_get_text(page, target = pz_loc(".task-title", which = "first"))
#> [1] "Buy milk"
pz_close(page)