表格
🌐 Forms
browser_type
在可编辑元素(输入框、文本区域、可编辑内容)中输入文本。
🌐 Type text into an editable element (input, textarea, contenteditable).
| 参数 | 类型 | 是否必填 | 描述 |
|---|---|---|---|
target | string | 是 | 来自快照的元素引用,或者唯一选择器 |
text | string | 是 | 要输入到元素中的文本 |
submit | boolean | 否 | 输入后是否按回车 |
slowly | boolean | 否 | 是否一个字符一个字符地输入。用于触发按键处理器;默认情况下文本会一次性填入 |
→ browser_type { target: "e5", text: "Buy groceries" }
→ browser_type { target: "e5", text: "Buy groceries", submit: true }
→ browser_type { target: "e8", text: "search query", slowly: true }
browser_fill_form
一次调用即可填写多个表单字段。支持文本框、复选框、单选按钮、下拉框和滑块。这比为每个字段单独调用 browser_type 和 browser_click 更高效。
🌐 Fill multiple form fields in one call. Supports textboxes, checkboxes, radio buttons, comboboxes, and sliders. This is more efficient than calling browser_type and browser_click for each field individually.
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
fields | 对象数组 | 是 | 需要填写的字段 |
每个字段都是一个对象:
🌐 Each field is an object:
| 字段键 | 类型 | 是否必填 | 描述 |
|---|---|---|---|
name | 字符串 | 是 | 可读的字段名称 |
target | 字符串 | 是 | 元素引用或选择器 |
type | 字符串 | 是 | textbox、checkbox、radio、combobox 或 slider |
value | 字符串 | 是 | 要填写的值。对于复选框或单选框使用 "true" / "false";对于下拉框使用选项的文本 |
→ browser_snapshot
- textbox "First name" [ref=e3]
- textbox "Last name" [ref=e5]
- textbox "Email" [ref=e7]
- checkbox "Accept terms" [ref=e9]
- combobox "Country" [ref=e11]
- radio "Annual plan" [ref=e15]
→ browser_fill_form {
fields: [
{ name: "First name", target: "e3", type: "textbox", value: "Alice" },
{ name: "Last name", target: "e5", type: "textbox", value: "Smith" },
{ name: "Email", target: "e7", type: "textbox", value: "alice@example.com" },
{ name: "Accept terms", target: "e9", type: "checkbox", value: "true" },
{ name: "Country", target: "e11", type: "combobox", value: "United States" },
{ name: "Annual plan", target: "e15", type: "radio", value: "true" }
]
}
要切换单个复选框或单选按钮,可以用 browser_click 点击它,或者使用 browser_fill_form 配合 type: "checkbox"(或 "radio")以及 value: "true" / "false"。
秘密
🌐 Secrets
传递给 browser_type 和 browser_fill_form 的值会与通过 --secrets <path> 提供的 secrets 文件(dotenv 格式)进行匹配。在值到达页面之前,会将匹配的占位符替换为真实值,生成的代码显示的是 SECRET_<name> 而不是实际值。
🌐 Values passed to browser_type and browser_fill_form are matched against the secrets file supplied
with --secrets <path> (dotenv format). A matching placeholder is substituted with the real value
before it reaches the page, and the generated code shows SECRET_<name> instead of the value.
工作流程:完成多步骤表单
🌐 Workflow: completing a multi-step form
You: Fill out the registration form on this page.
→ browser_snapshot
// Page 1: Personal info
- textbox "Email" [ref=e3]
- textbox "Password" [ref=e5]
- button "Next" [ref=e7]
→ browser_type { target: "e3", text: "alice@example.com" }
→ browser_type { target: "e5", text: "s3cureP@ss!" }
→ browser_click { target: "e7" }
// Page 2: Profile
- textbox "Display name" [ref=e3]
- combobox "Timezone" [ref=e5]
- checkbox "Subscribe to newsletter" [ref=e7]
- button "Create account" [ref=e9]
→ browser_fill_form {
fields: [
{ name: "Display name", target: "e3", type: "textbox", value: "Alice S." },
{ name: "Timezone", target: "e5", type: "combobox", value: "US/Pacific" },
{ name: "Subscribe", target: "e7", type: "checkbox", value: "true" }
]
}
→ browser_click { target: "e9" }