键盘与鼠标
🌐 Keyboard & Mouse
Keyboard
browser_press_key
按一个键或按键组合。
🌐 Press a key or key combination.
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
key | string | 是 | 要按的键 |
常用按键: Enter、Tab、Escape、Backspace、Delete、ArrowUp、ArrowDown、ArrowLeft、ArrowRight、Home、End、PageUp、PageDown
组合键: Control+a, Control+c, Control+v, Shift+Tab, Alt+F4
→ browser_press_key { key: "Enter" } // submit form
→ browser_press_key { key: "Tab" } // move to next field
→ browser_press_key { key: "Escape" } // close modal
→ browser_press_key { key: "Control+a" } // select all text
→ browser_press_key { key: "ArrowDown" } // navigate dropdown
browser_type
在元素中输入文本。详情请参见 Forms。
🌐 Type text into an element. See Forms for details.
鼠标(视觉模式)
🌐 Mouse (Vision mode)
当启用 视觉 功能(--caps=vision)时,这些工具可用。它们使用截图中的像素坐标,而不是快照中的元素引用。
🌐 These tools are available when the vision capability is enabled (--caps=vision). They use pixel coordinates from screenshots rather than element refs from snapshots.
browser_mouse_move_xy
| 参数 | 类型 | 是否必填 | 描述 |
|---|---|---|---|
x | 数字 | 是 | X 坐标(像素) |
y | 数字 | 是 | Y 坐标(像素) |
浏览器_鼠标按下 / 浏览器_鼠标抬起
🌐 browser_mouse_down / browser_mouse_up
在当前位置按下或释放鼠标按钮。
🌐 Press or release the mouse button at the current position.
browser_mouse_wheel
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
deltaX | 数字 | 是 | 水平滚动(像素) |
deltaY | 数字 | 是 | 垂直滚动(像素,正值 = 向下) |
browser_mouse_click_xy
在特定坐标点击,无需先移动。
🌐 Click at specific coordinates without needing to move first.
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
x | 数字 | 是 | X 坐标 |
y | 数字 | 是 | Y 坐标 |
button | 字符串 | 否 | left(默认)、right 或 middle |
clickCount | 数字 | 否 | 点击次数(双击为 2) |
delay | 数字 | 否 | 按下与抬起之间的延迟(毫秒) |
→ browser_mouse_click_xy { x: 150, y: 300 }
→ browser_mouse_click_xy { x: 150, y: 300, clickCount: 2 } // double-click
browser_mouse_drag_xy
从一个位置拖到另一个位置。
🌐 Drag from one position to another.
| 参数 | 类型 | 是否必需 | 描述 |
|---|---|---|---|
startX | 数字 | 是 | 起始 X 坐标 |
startY | 数字 | 是 | 起始 Y 坐标 |
endX | 数字 | 是 | 结束 X 坐标 |
endY | 数字 | 是 | 结束 Y 坐标 |
→ browser_mouse_drag_xy { startX: 100, startY: 200, endX: 400, endY: 200 }
何时使用鼠标工具
🌐 When to use mouse tools
| 场景 | 用途 |
|---|---|
| 点击按钮、链接或表单元素 | 带引用的 browser_click(默认) |
| 基于画布的应用(绘图、地图) | 带视觉的鼠标工具 |
| 无辅助功能的自定义 UI 控件 | 带视觉的鼠标工具 |
| 精确像素目标的拖动交互 | 带视觉的鼠标工具 |
对于大多数 web 应用,来自可访问性快照的引用比坐标更可靠。仅在可访问性树未显示所需元素时使用鼠标工具。
🌐 For most web applications, refs from accessibility snapshots are more reliable than coordinates. Use mouse tools only when the accessibility tree doesn't expose the elements you need.