选择器

引用(推荐)

引用(Refs)可从快照中提供确定性的元素选择。非常适合人工智能代理。

# 1. 获取带有引用的快照
agent-browser snapshot
# 输出:
# - 标题 "示例域名" [ref=e1] [level=1]
# - 按钮 "提交" [ref=e2]
# - 文本框 "电子邮件" [ref=e3]
# - 链接 "了解更多" [ref=e4]

# 2. 使用引用进行交互
agent-browser click @e2                   # 点击按钮
agent-browser fill @e3 "[email protected]" # 填写文本框
agent-browser get text @e1                # 获取标题文本
agent-browser hover @e4                   # 悬停于链接上

为什么使用引用?

  • 确定性 - 引用指向快照中的确切元素
  • 快速 - 无需重新查询 DOM
  • 适合 AI - 大语言模型可以可靠地解析和使用引用

CSS 选择器

agent-browser click "#id"
agent-browser click ".class"
agent-browser click "div > button"
agent-browser click "[data-testid='submit']"

文本与 XPath

agent-browser click "text=提交"
agent-browser click "xpath=//button[@type='submit']"

语义定位器

通过角色、标签或其他语义属性查找元素:

agent-browser find role button click --name "提交"
agent-browser find label "电子邮件" fill "[email protected]"
agent-browser find placeholder "搜索..." fill "查询"
agent-browser find testid "submit-btn" click