对话框
🌐 Dialogs
处理会阻碍页面互动的浏览器对话框(警告、确认、提示、离开前确认)。
🌐 Handle browser dialogs (alert, confirm, prompt, beforeunload) that block page interaction.
browser_handle_dialog
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
accept | 布尔值 | 是 | true 接受, false 拒绝 |
promptText | 字符串 | 否 | 提示对话框的提示文本 |
当对话框打开时,其他所有工具都无法运行,并会报告模态状态:
🌐 While a dialog is open, every other tool refuses to run and reports the modal state instead:
### Modal state
- ["alert" dialog with message "Alert"]: can be handled by browser_handle_dialog
在继续之前处理对话。
🌐 Handle the dialog before continuing.
警告对话框
🌐 Alert dialog
→ browser_click { target: "e5" }
### Modal state
- ["alert" dialog with message "Item deleted"]: can be handled by browser_handle_dialog
→ browser_handle_dialog { accept: true }
确认对话框
🌐 Confirm dialog
→ browser_click { target: "e10" }
### Modal state
- ["confirm" dialog with message "Are you sure you want to delete this?"]: can be handled by browser_handle_dialog
→ browser_handle_dialog { accept: true } // click OK
→ browser_handle_dialog { accept: false } // click Cancel
提示对话框
🌐 Prompt dialog
→ browser_click { target: "e8" }
### Modal state
- ["prompt" dialog with message "Enter your name:"]: can be handled by browser_handle_dialog
→ browser_handle_dialog { accept: true, promptText: "My new name" }
工作流程
🌐 Workflow
→ browser_click { target: "e12" }
### Modal state
- ["confirm" dialog with message "Discard unsaved changes?"]: can be handled by browser_handle_dialog
→ browser_handle_dialog { accept: true }
→ browser_snapshot
// Page now shows updated state after the dialog was accepted
note
文件选择器的报告方式相同,并且使用 browser_file_upload 清除,而不是 browser_handle_dialog。见 文件上传。