跳转至

选择器

Refs 可从快照中确定性选择元素,最适合 AI 智能体使用。

# 1. Get snapshot with refs
agent-browser snapshot
# Output:
# - heading "Example Domain" [ref=e1] [level=1]
# - button "Submit" [ref=e2]
# - textbox "Email" [ref=e3]
# - link "Learn more" [ref=e4]

# 2. Use refs to interact
agent-browser click @e2                   # Click the button
agent-browser fill @e3 "test@example.com" # Fill the textbox
agent-browser get text @e1                # Get heading text
agent-browser hover @e4                   # Hover the link

为什么使用 Refs?

  • 确定性 - Ref 指向快照中的精确元素
  • 快速 - 无需重新查询 DOM
  • AI 友好 - LLM 能够可靠地解析和使用 refs

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=Submit"
agent-browser click "xpath=//button[@type='submit']"

语义定位器

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

agent-browser find role button click --name "Submit"
agent-browser find role heading text --name "Skills"     # implicit roles work: <h2>=heading, <ul>=list, top-level <header>=banner
agent-browser find label "Email" fill "test@test.com"
agent-browser find placeholder "Search..." fill "query"
agent-browser find testid "submit-btn" click

本页原文 Markdown:在 AtomGit 查看·内容源自开源项目 agen/agent-browser