Run JavaScript in the app’s window. A script runs in the current frame (the
frame entered, or the top page): its window
and document. Paths follow http://127.0.0.1:4445/{token}; see the
overview for the reply format and the errors.
The script is the body of a function made with the current frame’s
Function, called with that frame’s window as this and the arguments as
arguments. It may run for as long as the session’s
script timeout allows (30 seconds by default,
no limit with null), then the command answers 500 script timeout. The
server answers one request at a time, so a long script holds up the requests
behind it.
Execute script#
POST /session/{sessionId}/execute/sync
The value the script returns is the result. A returned promise is awaited first.
The current session’s id.
The function body.
The arguments. An element reference becomes the element, in arrays and objects too.
Default: "[]"
Execute async script#
POST /session/{sessionId}/execute/async
The script gets one more argument, last: a callback. The value it is called with is the result.
The current session’s id.
The function body.
The arguments, before the callback. An element reference becomes the element, in arrays and objects too.
Default: "[]"
Results#
A result goes back as JSON:
- an element becomes its reference;
- an array, a
NodeListor anHTMLCollectionbecomes an array; - another object is copied key by key (its own enumerable keys);
undefinedbecomesnull.
Errors#
| Status | error | When |
|---|---|---|
| 400 | invalid argument | script is missing or not a string (`script` is missing). |
| 404 | no such element, stale element reference | An element in args is unknown or gone. |
| 404 | no such frame | The frame entered is gone or no longer same-origin. |
| 500 | javascript error | The script threw, or its promise was rejected; the message is the error’s. |
| 500 | script timeout | The script did not finish within the script timeout. |