browsingContext.handleUserPrompt command
The browsingContext.handleUserPrompt command of the browsingContext module closes an open user prompt: an alert(), confirm(), prompt(), or beforeunload prompt.
Syntax
/* With required parameters */
{
"method": "browsingContext.handleUserPrompt",
"params": {
"context": "93ee5bd6-d256-4608-a002-9a8995cc0e5f"
}
}
/* With required and optional parameters */
{
"method": "browsingContext.handleUserPrompt",
"params": {
"context": "93ee5bd6-d256-4608-a002-9a8995cc0e5f",
"accept": true,
"userText": "some input text"
}
}
Parameters
The params field contains:
acceptOptional-
A boolean that indicates whether to accept or dismiss the prompt; its effect depends on the prompt type.
For an
alert(), this value has no effect and the prompt is always acknowledged. For the other prompt types:-
true: This is the default.For a
confirm(), the action is confirmed. For aprompt(), the prompt is submitted with the value ofuserText. For abeforeunloadprompt, the navigation is confirmed. -
false:For a
confirm(), the action is declined. For aprompt(), the prompt is canceled. For abeforeunloadprompt, the navigation is refused.
-
context-
A string that contains the ID of the context that has the user prompt to close. Context IDs are returned by commands such as
browsingContext.getTree. userTextOptional-
A string that specifies the value to submit for a
prompt(). This field is ignored for prompt types other thanprompt(). If not specified, it defaults to an empty string.
Return value
The result field in the response is an empty object ({}).
The browsingContext.userPromptClosed event fires when the prompt is closed.
Errors
invalid argument-
A required parameter is missing or has an invalid type.
no such frame-
No context with the given context ID is found.
no such alert-
The context specified by
contextdoes not have a user prompt.
Examples
>Accepting a confirm() prompt
With a WebDriver BiDi connection and an active session, suppose a page calls confirm(), opening a prompt that blocks the page.
Listen for the browsingContext.userPromptOpened event to detect the prompt, then send the following message to accept it:
{
"id": 1,
"method": "browsingContext.handleUserPrompt",
"params": {
"context": "5e5e96e8-5247-4f22-9b35-a4a2d841cbaa",
"accept": true
}
}
The browser closes the prompt and responds as follows:
{
"id": 1,
"type": "success",
"result": {}
}
Accepting a prompt() with text
Using the same connection and session, suppose a page calls prompt() and shows the resulting text input dialog.
Send the following message to submit a value:
{
"id": 2,
"method": "browsingContext.handleUserPrompt",
"params": {
"context": "5e5e96e8-5247-4f22-9b35-a4a2d841cbaa",
"accept": true,
"userText": "example input"
}
}
The browser responds as follows:
{
"id": 2,
"type": "success",
"result": {}
}
Specifications
| Specification |
|---|
| WebDriver BiDi> # command-browsingContext-handleUserPrompt> |
Browser compatibility
See also
browsingContext.getTreecommandbrowsingContext.navigatecommandbrowsingContext.reloadcommandbrowsingContext.userPromptOpenedeventbrowsingContext.userPromptClosedevent