AgentSkillsCN

playwright-mcp-cli

自动化浏览器交互,用于Web测试、表单填写、截图采集与数据提取。当用户需要浏览网站、与网页互动、填写表单、截取屏幕截图、测试Web应用,或从网页中提取信息时使用此功能。支持多标签页工作流、网络监控、追踪、视频录制以及测试生成等高级功能。

SKILL.md
--- frontmatter
name: playwright-mcp-cli
description: Automates browser interactions for web testing, form filling, screenshots, and data extraction. Use when the user needs to navigate websites, interact with web pages, fill forms, take screenshots, test web applications, or extract information from web pages. Supports advanced features like multi-tab workflows, network monitoring, tracing, video recording, and test generation.

Browser Automation with Playwright MCP CLI

Automates browser interactions using the playwright-cli command-line tool.

Core Workflow

  1. Navigate: playwright-cli open https://example.com
  2. Snapshot: playwright-cli snapshot to get element refs (e1, e2, etc.)
  3. Interact: Use refs to click, fill, type, etc.
  4. Re-snapshot: After significant changes to get updated refs

Quick Start

bash
# Open a page
playwright-cli open https://example.com

# Get element references
playwright-cli snapshot

# Interact with elements (use refs from snapshot)
playwright-cli click e15
playwright-cli fill e5 "user@example.com"
playwright-cli type "search query"
playwright-cli press Enter

# Capture results
playwright-cli screenshot

Common Tasks

Form Submission

bash
playwright-cli open https://example.com/form
playwright-cli snapshot
playwright-cli fill e1 "user@example.com"
playwright-cli fill e2 "password123"
playwright-cli click e3
playwright-cli snapshot

Multi-Tab Workflow

bash
playwright-cli open https://example.com
playwright-cli tab-new https://example.com/other
playwright-cli tab-list
playwright-cli tab-select 0
playwright-cli snapshot

Screenshots and PDF

bash
playwright-cli screenshot              # Full page
playwright-cli screenshot e5           # Specific element
playwright-cli pdf                     # Save as PDF

Debugging

bash
playwright-cli console                 # Console messages
playwright-cli console warning         # Filter by level
playwright-cli network                 # Network requests

Core Commands

Navigation & Interaction

  • open [url] - Open URL
  • close - Close page
  • click <ref> - Click element
  • fill <ref> <text> - Fill input
  • type <text> - Type in focused element
  • press <key> - Press keyboard key
  • snapshot - Get element refs

Tabs

  • tab-list - List all tabs
  • tab-new [url] - Create new tab
  • tab-close [index] - Close tab
  • tab-select <index> - Switch tab

DevTools

  • console [level] - Console logs
  • network - Network requests
  • tracing-start/stop - Record trace
  • video-start/stop - Record video

Sessions

  • --session=name - Named session
  • session-list - List sessions
  • session-stop [name] - Stop session
  • session-delete [name] - Delete session

Advanced Features

For detailed guides on advanced topics, see: