Module Webdriver_cohttp_async.Wait

Even though the browser attempts to complete most operations before giving back control, some commands might trigger too soon and raise an error. The recommended strategy is to sleep and retry the operation repeatedly until it succeeds.

val retry : ?⁠max:int -> ?⁠sleep:int -> ?⁠errors:Error.error list -> 'a cmd -> 'a cmd

retry cmd attempts to execute cmd. If it fails with a recoverable error, the execution sleeps for a bit to give the browser a chance to catch up, then the operation is retried until it succeeds or the max time is reached.

let* e = find_first `css "#id" in (* might raise `no_such_element *)
(* vs *)
let* e = Wait.retry @@ find_first `css "#id" in (* deterministic *)
val until : ?⁠max:int -> ?⁠sleep:int -> ?⁠errors:Error.error list -> bool cmd -> unit cmd

until condition behaves like retry condition, but the predicate must also be satisfied at the end.

Raises `unspecified "condition" if the max time is reached and the condition is still unsatisfied.

let* url = current_url in
let* () = send_keys input ("hello" ^ Key.Enter) in
let* () = Wait.until @@ map (( <> ) url ) current_url in
(* blocks until the form is actually submitted. *)