Skip to main content

表格

🌐 Forms

browser_type

在可编辑元素(输入框、文本区域、可编辑内容)中输入文本。

🌐 Type text into an editable element (input, textarea, contenteditable).

参数类型是否必填描述
targetstring来自快照的元素引用,或者唯一选择器
textstring要输入到元素中的文本
submitboolean输入后是否按回车
slowlyboolean是否一个字符一个字符地输入。用于触发按键处理器;默认情况下文本会一次性填入
→ 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_typebrowser_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字符串textboxcheckboxradiocomboboxslider
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" }
]
}
note

要切换单个复选框或单选按钮,可以用 browser_click 点击它,或者使用 browser_fill_form 配合 type: "checkbox"(或 "radio")以及 value: "true" / "false"

秘密

🌐 Secrets

传递给 browser_typebrowser_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" }