playwright-cli
Drive a browser from the terminal with playwright-cli: snapshot the page, then act on elements by ref. Use when automating browser interactions, filling web forms, testing UIs, or driving logged-in web apps from the command line.
适合你,如果你想用命令行驱动浏览器完成测试或自动化任务
npx oh-my-skill add lexler/skill-factory/playwright-clicurl -fsSL https://oh-my-skill.com/install.sh | bash -s -- lexler/skill-factory/playwright-clinpx oh-my-skill verify lexler/skill-factory/playwright-cli怎么用
商店整理自技能原文 · 版本 2eae60e · 表述以原文为准装上后,你可以通过终端使用 playwright-cli 驱动浏览器:对页面进行快照,然后通过引用(ref)对元素进行操作,如点击、填写、选择等。
当需要自动化浏览器交互、填写网页表单、测试 UI 或从命令行驱动已登录的 Web 应用时触发。
技能原文 SKILL.md
STARTER_CHARACTER = 🎭
playwright-cli
Driving a browser from the shell. Each command prints the executed Playwright code, the page state, and a fresh snapshot.
The loop
Snapshot to see the page, act on an element by its ref, snapshot again.
playwright-cli snapshot # accessibility tree with [ref=e8] handles playwright-cli click e8 # act on a ref playwright-cli snapshot # confirm the result
Refs are not stable. Any DOM change renumbers them — re-snapshot before acting on a page that just changed. Acting on a stale ref hits the wrong element or none.
For a large page, snapshot a region instead of the whole tree: snapshot e34 or snapshot --depth=4.
Targeting elements
A target is one of three things — a ref, a CSS selector, or a Playwright locator:
playwright-cli click e8
playwright-cli click ".todo-list .toggle"
playwright-cli click "getByRole('button', { name: 'Submit' })"
playwright-cli click "getByText('buy milk')"
A bare descriptive phrase is not a target. click "the submit button" is parsed as a CSS selector and fails with "does not match any elements". Prefer refs; reach for getByRole/getByText when a ref won't survive a re-render.
Key commands
playwright-cli goto https://example.com playwright-cli fill e5 "user@example.com" --submit # clear, type, then Enter — one step playwright-cli type "free text into the focused element" playwright-cli press Enter # also: Tab, Escape, ArrowDown playwright-cli select e9 "option-value" playwright-cli check e12 # uncheck / hover / dblclick likewise playwright-cli screenshot # saves to .playwright-cli/
fill works on React/controlled inputs where raw DOM events don't. After filling, the field must blur before dependent values (totals, validation) update — --submit or a following press Tab does that.
Inspecting and verifying
playwright-cli eval "el => el.getAttribute('data-testid')" e5 # attributes the snapshot hides
playwright-cli console # page console messages
playwright-cli requests # network log, then `request <n>`
--raw strips the wrapper so output pipes, and proves what an action changed:
playwright-cli --raw snapshot > before.yml playwright-cli click e8 playwright-cli --raw snapshot > after.yml diff before.yml after.yml
Sessions
open launches a fresh browser; --persistent keeps cookies across runs. To drive an already-running, logged-in browser instead, attach over CDP. See [references/attaching-to-chrome.md](references/attaching-to-chrome.md).
Name parallel browsers with -s=<name> (omit it for the implicit default session). playwright-cli list, close, close-all.
Full command set
The above is the working subset. The CLI ships its own exhaustive reference — tabs, storage, mocking, tracing, video, codegen. See [references/full-command-reference.md](references/full-command-reference.md).