drissionpage-cli 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- drissionpage_cli-0.1.0/LICENSE +21 -0
- drissionpage_cli-0.1.0/PKG-INFO +314 -0
- drissionpage_cli-0.1.0/README.md +288 -0
- drissionpage_cli-0.1.0/drissionpage_cli/__init__.py +1372 -0
- drissionpage_cli-0.1.0/drissionpage_cli/skills/drissionpage-cli/SKILL.md +249 -0
- drissionpage_cli-0.1.0/drissionpage_cli/skills/drissionpage-cli/references/dual-mode.md +91 -0
- drissionpage_cli-0.1.0/drissionpage_cli/skills/drissionpage-cli/references/element-locators.md +116 -0
- drissionpage_cli-0.1.0/drissionpage_cli/skills/drissionpage-cli/references/network-listening.md +121 -0
- drissionpage_cli-0.1.0/drissionpage_cli/skills/drissionpage-cli/references/running-code.md +182 -0
- drissionpage_cli-0.1.0/drissionpage_cli/skills/drissionpage-cli/references/screenshots-pdf.md +93 -0
- drissionpage_cli-0.1.0/drissionpage_cli/skills/drissionpage-cli/references/session-management.md +136 -0
- drissionpage_cli-0.1.0/drissionpage_cli/skills/drissionpage-cli/references/storage-state.md +144 -0
- drissionpage_cli-0.1.0/drissionpage_cli.egg-info/PKG-INFO +314 -0
- drissionpage_cli-0.1.0/drissionpage_cli.egg-info/SOURCES.txt +20 -0
- drissionpage_cli-0.1.0/drissionpage_cli.egg-info/dependency_links.txt +1 -0
- drissionpage_cli-0.1.0/drissionpage_cli.egg-info/entry_points.txt +2 -0
- drissionpage_cli-0.1.0/drissionpage_cli.egg-info/requires.txt +1 -0
- drissionpage_cli-0.1.0/drissionpage_cli.egg-info/top_level.txt +1 -0
- drissionpage_cli-0.1.0/pyproject.toml +44 -0
- drissionpage_cli-0.1.0/setup.cfg +4 -0
- drissionpage_cli-0.1.0/tests/test_integration.py +483 -0
- drissionpage_cli-0.1.0/tests/test_unit.py +1058 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Marquez
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: drissionpage-cli
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: DrissionPage CLI - Token-efficient browser automation for coding agents
|
|
5
|
+
Author: DrissionPage-MCP Contributors
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/nicekate/DrissionPage-MCP
|
|
8
|
+
Project-URL: Repository, https://github.com/nicekate/DrissionPage-MCP
|
|
9
|
+
Keywords: browser,automation,cli,drissionpage,web,scraping
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Topic :: Software Development :: Testing
|
|
20
|
+
Classifier: Topic :: Internet :: WWW/HTTP :: Browsers
|
|
21
|
+
Requires-Python: >=3.8
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Requires-Dist: DrissionPage>=4.0.0
|
|
25
|
+
Dynamic: license-file
|
|
26
|
+
|
|
27
|
+
# DrissionPage-cli
|
|
28
|
+
|
|
29
|
+
Token-efficient browser automation CLI for coding agents, powered by [DrissionPage](https://DrissionPage.cn).
|
|
30
|
+
|
|
31
|
+
Mirrors the architecture of [playwright-cli](https://github.com/microsoft/playwright-cli) but uses DrissionPage as the backend — pure Python, no Node.js required.
|
|
32
|
+
|
|
33
|
+
## Why CLI + Skills over MCP
|
|
34
|
+
|
|
35
|
+
Modern coding agents (Claude Code, GitHub Copilot, etc.) increasingly favour CLI-based workflows exposed as **SKILLs** over MCP because CLI invocations are more token-efficient: they avoid loading large tool schemas and verbose accessibility trees into the model context. This makes CLI + SKILLs better suited for high-throughput agents that must balance browser automation with large codebases within limited context windows.
|
|
36
|
+
|
|
37
|
+
## Requirements
|
|
38
|
+
|
|
39
|
+
- Python 3.8+
|
|
40
|
+
- Chrome / Chromium browser installed
|
|
41
|
+
|
|
42
|
+
## Installation
|
|
43
|
+
|
|
44
|
+
### From source (development)
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
git clone https://github.com/nicekate/DrissionPage-MCP.git
|
|
48
|
+
cd DrissionPage-MCP/DrissionPage-cli
|
|
49
|
+
pip install -e .
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Dependencies only
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
pip install DrissionPage>=4.0.0
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
After installation the `drissionpage-cli` command is available globally:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
drissionpage-cli --version
|
|
62
|
+
drissionpage-cli --help
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Install skills for Claude Code
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
drissionpage-cli install --skills
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
This copies the SKILL.md and reference guides into `.claude/skills/drissionpage-cli/` so that Claude Code (or any compatible agent) can discover them automatically.
|
|
72
|
+
|
|
73
|
+
## Quick Start
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
# Open a browser (headless by default)
|
|
77
|
+
drissionpage-cli open https://example.com
|
|
78
|
+
|
|
79
|
+
# Take a snapshot of the page
|
|
80
|
+
drissionpage-cli snapshot
|
|
81
|
+
|
|
82
|
+
# Interact with elements using DrissionPage locators
|
|
83
|
+
drissionpage-cli click "@id=submit"
|
|
84
|
+
drissionpage-cli fill "css:input[name=email]" "user@example.com" --submit
|
|
85
|
+
|
|
86
|
+
# Evaluate JavaScript
|
|
87
|
+
drissionpage-cli eval "return document.title"
|
|
88
|
+
|
|
89
|
+
# Take a screenshot
|
|
90
|
+
drissionpage-cli screenshot --filename=result.png
|
|
91
|
+
|
|
92
|
+
# Close the browser
|
|
93
|
+
drissionpage-cli close
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Headed mode
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
drissionpage-cli open https://example.com --headed
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Commands
|
|
103
|
+
|
|
104
|
+
### Core
|
|
105
|
+
|
|
106
|
+
| Command | Description |
|
|
107
|
+
|---------|-------------|
|
|
108
|
+
| `open [url]` | Open browser, optionally navigate to URL |
|
|
109
|
+
| `goto <url>` | Navigate to a URL |
|
|
110
|
+
| `click <ref>` | Click an element |
|
|
111
|
+
| `dblclick <ref>` | Double-click an element |
|
|
112
|
+
| `right-click <ref>` | Right-click an element |
|
|
113
|
+
| `type <text> [ref]` | Type text into element |
|
|
114
|
+
| `fill <ref> <text> [--submit]` | Clear and fill text (optionally press Enter) |
|
|
115
|
+
| `hover <ref>` | Hover over element |
|
|
116
|
+
| `drag <startRef> <endRef>` | Drag element to another |
|
|
117
|
+
| `select <ref> <value>` | Select dropdown option |
|
|
118
|
+
| `check <ref>` / `uncheck <ref>` | Check / uncheck a checkbox |
|
|
119
|
+
| `upload <ref> <file>` | Upload a file |
|
|
120
|
+
| `snapshot [ref] [--filename=f]` | Capture page or element snapshot |
|
|
121
|
+
| `eval <expr> [ref]` | Evaluate JavaScript on page or element |
|
|
122
|
+
| `run-code <code> [--filename=f]` | Run arbitrary DrissionPage Python code |
|
|
123
|
+
| `screenshot [ref] [--filename=f]` | Take a screenshot |
|
|
124
|
+
| `pdf [--filename=f]` | Save page as PDF |
|
|
125
|
+
| `resize <w> <h>` | Resize the browser window |
|
|
126
|
+
| `dialog-accept [text]` | Accept a dialog |
|
|
127
|
+
| `dialog-dismiss` | Dismiss a dialog |
|
|
128
|
+
| `close` | Close the browser |
|
|
129
|
+
|
|
130
|
+
### Navigation
|
|
131
|
+
|
|
132
|
+
| Command | Description |
|
|
133
|
+
|---------|-------------|
|
|
134
|
+
| `go-back` | Go back |
|
|
135
|
+
| `go-forward` | Go forward |
|
|
136
|
+
| `reload` | Reload page |
|
|
137
|
+
|
|
138
|
+
### Keyboard & Mouse
|
|
139
|
+
|
|
140
|
+
| Command | Description |
|
|
141
|
+
|---------|-------------|
|
|
142
|
+
| `press <key>` | Press a key (Enter, ArrowDown, Tab, etc.) |
|
|
143
|
+
| `mousemove <x> <y>` | Move mouse to coordinates |
|
|
144
|
+
| `mousedown [button]` | Press mouse button |
|
|
145
|
+
| `mouseup [button]` | Release mouse button |
|
|
146
|
+
| `scroll <dx> <dy>` | Scroll the page |
|
|
147
|
+
|
|
148
|
+
### Tabs
|
|
149
|
+
|
|
150
|
+
| Command | Description |
|
|
151
|
+
|---------|-------------|
|
|
152
|
+
| `tab-list` | List all tabs |
|
|
153
|
+
| `tab-new [url]` | Create new tab |
|
|
154
|
+
| `tab-close [index]` | Close a tab |
|
|
155
|
+
| `tab-select <index>` | Select a tab |
|
|
156
|
+
|
|
157
|
+
### Cookies & Storage
|
|
158
|
+
|
|
159
|
+
| Command | Description |
|
|
160
|
+
|---------|-------------|
|
|
161
|
+
| `cookie-list [--domain=d]` | List cookies |
|
|
162
|
+
| `cookie-get <name>` | Get a cookie |
|
|
163
|
+
| `cookie-set <name> <val> [opts]` | Set a cookie |
|
|
164
|
+
| `cookie-delete <name>` | Delete a cookie |
|
|
165
|
+
| `cookie-clear` | Clear all cookies |
|
|
166
|
+
| `localstorage-list\|get\|set\|delete\|clear` | Manage localStorage |
|
|
167
|
+
| `sessionstorage-list\|get\|set\|delete\|clear` | Manage sessionStorage |
|
|
168
|
+
| `state-save [filename]` | Save cookies + storage to JSON |
|
|
169
|
+
| `state-load <filename>` | Restore cookies + storage from JSON |
|
|
170
|
+
|
|
171
|
+
### Session Management
|
|
172
|
+
|
|
173
|
+
| Command | Description |
|
|
174
|
+
|---------|-------------|
|
|
175
|
+
| `list` | List all active sessions |
|
|
176
|
+
| `close` | Close current session's browser |
|
|
177
|
+
| `close-all` | Close all sessions |
|
|
178
|
+
| `kill-all` | Kill all browser processes |
|
|
179
|
+
| `delete-data` | Delete user data for a session |
|
|
180
|
+
|
|
181
|
+
## Targeting Elements
|
|
182
|
+
|
|
183
|
+
DrissionPage supports rich locator syntax:
|
|
184
|
+
|
|
185
|
+
```bash
|
|
186
|
+
# CSS selector
|
|
187
|
+
drissionpage-cli click "css:#main > button.submit"
|
|
188
|
+
|
|
189
|
+
# XPath
|
|
190
|
+
drissionpage-cli click "xpath://button[@id='submit']"
|
|
191
|
+
|
|
192
|
+
# Text content
|
|
193
|
+
drissionpage-cli click "text:Submit"
|
|
194
|
+
|
|
195
|
+
# Tag name
|
|
196
|
+
drissionpage-cli click "tag:button"
|
|
197
|
+
|
|
198
|
+
# Attribute matching
|
|
199
|
+
drissionpage-cli click "@id=submit"
|
|
200
|
+
drissionpage-cli click "@class:btn" # contains
|
|
201
|
+
drissionpage-cli click "@name^=user" # starts with
|
|
202
|
+
drissionpage-cli click "@data-testid=login"
|
|
203
|
+
|
|
204
|
+
# Combined (AND)
|
|
205
|
+
drissionpage-cli click "@@tag()=button@@text()=Submit"
|
|
206
|
+
|
|
207
|
+
# Combined (OR)
|
|
208
|
+
drissionpage-cli click "@|id=btn1@id=btn2"
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
## Named Sessions
|
|
212
|
+
|
|
213
|
+
Run multiple isolated browser instances concurrently:
|
|
214
|
+
|
|
215
|
+
```bash
|
|
216
|
+
drissionpage-cli -s=auth open https://app.example.com/login
|
|
217
|
+
drissionpage-cli -s=scrape open https://data.example.com
|
|
218
|
+
drissionpage-cli list
|
|
219
|
+
drissionpage-cli close-all
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
Or set a default session via environment variable:
|
|
223
|
+
|
|
224
|
+
```bash
|
|
225
|
+
DRISSIONPAGE_CLI_SESSION=myproject drissionpage-cli open https://example.com
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
## Running Custom Code
|
|
229
|
+
|
|
230
|
+
Execute arbitrary DrissionPage Python code with `run-code`. The `page` variable is the active `ChromiumPage` instance. Set `result` to output a return value.
|
|
231
|
+
|
|
232
|
+
```bash
|
|
233
|
+
drissionpage-cli run-code "result = page.title"
|
|
234
|
+
drissionpage-cli run-code "
|
|
235
|
+
eles = page.eles('tag:a')
|
|
236
|
+
result = [{'text': a.text, 'href': a.link} for a in eles if a.link]
|
|
237
|
+
"
|
|
238
|
+
drissionpage-cli run-code --filename=myscript.py
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
## Testing
|
|
242
|
+
|
|
243
|
+
The project includes two test suites:
|
|
244
|
+
|
|
245
|
+
### Unit tests (no browser required)
|
|
246
|
+
|
|
247
|
+
92 tests covering the argument parser, session management, snapshot formatting, skill installation, state save/load, and all command handlers via mocks.
|
|
248
|
+
|
|
249
|
+
```bash
|
|
250
|
+
cd DrissionPage-cli
|
|
251
|
+
pip install pytest
|
|
252
|
+
python3 -m pytest tests/test_unit.py -v
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
### Integration tests (browser required)
|
|
256
|
+
|
|
257
|
+
30+ end-to-end tests that launch a real browser, navigate `data:` URLs, click elements, manage storage, take screenshots, etc.
|
|
258
|
+
|
|
259
|
+
```bash
|
|
260
|
+
python3 -m pytest tests/test_integration.py -v
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
To skip integration tests in CI (no browser available):
|
|
264
|
+
|
|
265
|
+
```bash
|
|
266
|
+
SKIP_INTEGRATION=1 python3 -m pytest tests/ -v
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
### Run all tests
|
|
270
|
+
|
|
271
|
+
```bash
|
|
272
|
+
python3 -m pytest tests/ -v
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
## Project Structure
|
|
276
|
+
|
|
277
|
+
```
|
|
278
|
+
DrissionPage-cli/
|
|
279
|
+
drissionpage_cli.py # Main CLI (40+ commands)
|
|
280
|
+
pyproject.toml # Python packaging
|
|
281
|
+
requirements.txt # DrissionPage>=4.0.0
|
|
282
|
+
pytest.ini # Test configuration
|
|
283
|
+
README.md
|
|
284
|
+
LICENSE
|
|
285
|
+
scripts/
|
|
286
|
+
update.py # Skill update script
|
|
287
|
+
skills/drissionpage-cli/
|
|
288
|
+
SKILL.md # Agent skill definition
|
|
289
|
+
references/
|
|
290
|
+
element-locators.md # CSS, XPath, text, attribute locators
|
|
291
|
+
running-code.md # run-code for custom automation
|
|
292
|
+
session-management.md # Multiple browser sessions
|
|
293
|
+
storage-state.md # Cookies, localStorage, sessionStorage
|
|
294
|
+
screenshots-pdf.md # Visual capture
|
|
295
|
+
network-listening.md # Network monitoring
|
|
296
|
+
dual-mode.md # Browser + HTTP requests mode
|
|
297
|
+
tests/
|
|
298
|
+
conftest.py # Shared fixtures
|
|
299
|
+
test_unit.py # 92 unit tests (mocked, no browser)
|
|
300
|
+
test_integration.py # 30+ integration tests (real browser)
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
## Environment Variables
|
|
304
|
+
|
|
305
|
+
| Variable | Description |
|
|
306
|
+
|----------|-------------|
|
|
307
|
+
| `DRISSIONPAGE_CLI_SESSION` | Default session name (default: `default`) |
|
|
308
|
+
| `DRISSIONPAGE_CLI_DIR` | CLI data directory (default: `.drissionpage-cli`) |
|
|
309
|
+
| `DRISSIONPAGE_CLI_DEBUG` | Set to `1` for full tracebacks on errors |
|
|
310
|
+
| `SKIP_INTEGRATION` | Set to `1` to skip browser integration tests |
|
|
311
|
+
|
|
312
|
+
## License
|
|
313
|
+
|
|
314
|
+
Apache-2.0
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
# DrissionPage-cli
|
|
2
|
+
|
|
3
|
+
Token-efficient browser automation CLI for coding agents, powered by [DrissionPage](https://DrissionPage.cn).
|
|
4
|
+
|
|
5
|
+
Mirrors the architecture of [playwright-cli](https://github.com/microsoft/playwright-cli) but uses DrissionPage as the backend — pure Python, no Node.js required.
|
|
6
|
+
|
|
7
|
+
## Why CLI + Skills over MCP
|
|
8
|
+
|
|
9
|
+
Modern coding agents (Claude Code, GitHub Copilot, etc.) increasingly favour CLI-based workflows exposed as **SKILLs** over MCP because CLI invocations are more token-efficient: they avoid loading large tool schemas and verbose accessibility trees into the model context. This makes CLI + SKILLs better suited for high-throughput agents that must balance browser automation with large codebases within limited context windows.
|
|
10
|
+
|
|
11
|
+
## Requirements
|
|
12
|
+
|
|
13
|
+
- Python 3.8+
|
|
14
|
+
- Chrome / Chromium browser installed
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
### From source (development)
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
git clone https://github.com/nicekate/DrissionPage-MCP.git
|
|
22
|
+
cd DrissionPage-MCP/DrissionPage-cli
|
|
23
|
+
pip install -e .
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### Dependencies only
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
pip install DrissionPage>=4.0.0
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
After installation the `drissionpage-cli` command is available globally:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
drissionpage-cli --version
|
|
36
|
+
drissionpage-cli --help
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Install skills for Claude Code
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
drissionpage-cli install --skills
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
This copies the SKILL.md and reference guides into `.claude/skills/drissionpage-cli/` so that Claude Code (or any compatible agent) can discover them automatically.
|
|
46
|
+
|
|
47
|
+
## Quick Start
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
# Open a browser (headless by default)
|
|
51
|
+
drissionpage-cli open https://example.com
|
|
52
|
+
|
|
53
|
+
# Take a snapshot of the page
|
|
54
|
+
drissionpage-cli snapshot
|
|
55
|
+
|
|
56
|
+
# Interact with elements using DrissionPage locators
|
|
57
|
+
drissionpage-cli click "@id=submit"
|
|
58
|
+
drissionpage-cli fill "css:input[name=email]" "user@example.com" --submit
|
|
59
|
+
|
|
60
|
+
# Evaluate JavaScript
|
|
61
|
+
drissionpage-cli eval "return document.title"
|
|
62
|
+
|
|
63
|
+
# Take a screenshot
|
|
64
|
+
drissionpage-cli screenshot --filename=result.png
|
|
65
|
+
|
|
66
|
+
# Close the browser
|
|
67
|
+
drissionpage-cli close
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Headed mode
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
drissionpage-cli open https://example.com --headed
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Commands
|
|
77
|
+
|
|
78
|
+
### Core
|
|
79
|
+
|
|
80
|
+
| Command | Description |
|
|
81
|
+
|---------|-------------|
|
|
82
|
+
| `open [url]` | Open browser, optionally navigate to URL |
|
|
83
|
+
| `goto <url>` | Navigate to a URL |
|
|
84
|
+
| `click <ref>` | Click an element |
|
|
85
|
+
| `dblclick <ref>` | Double-click an element |
|
|
86
|
+
| `right-click <ref>` | Right-click an element |
|
|
87
|
+
| `type <text> [ref]` | Type text into element |
|
|
88
|
+
| `fill <ref> <text> [--submit]` | Clear and fill text (optionally press Enter) |
|
|
89
|
+
| `hover <ref>` | Hover over element |
|
|
90
|
+
| `drag <startRef> <endRef>` | Drag element to another |
|
|
91
|
+
| `select <ref> <value>` | Select dropdown option |
|
|
92
|
+
| `check <ref>` / `uncheck <ref>` | Check / uncheck a checkbox |
|
|
93
|
+
| `upload <ref> <file>` | Upload a file |
|
|
94
|
+
| `snapshot [ref] [--filename=f]` | Capture page or element snapshot |
|
|
95
|
+
| `eval <expr> [ref]` | Evaluate JavaScript on page or element |
|
|
96
|
+
| `run-code <code> [--filename=f]` | Run arbitrary DrissionPage Python code |
|
|
97
|
+
| `screenshot [ref] [--filename=f]` | Take a screenshot |
|
|
98
|
+
| `pdf [--filename=f]` | Save page as PDF |
|
|
99
|
+
| `resize <w> <h>` | Resize the browser window |
|
|
100
|
+
| `dialog-accept [text]` | Accept a dialog |
|
|
101
|
+
| `dialog-dismiss` | Dismiss a dialog |
|
|
102
|
+
| `close` | Close the browser |
|
|
103
|
+
|
|
104
|
+
### Navigation
|
|
105
|
+
|
|
106
|
+
| Command | Description |
|
|
107
|
+
|---------|-------------|
|
|
108
|
+
| `go-back` | Go back |
|
|
109
|
+
| `go-forward` | Go forward |
|
|
110
|
+
| `reload` | Reload page |
|
|
111
|
+
|
|
112
|
+
### Keyboard & Mouse
|
|
113
|
+
|
|
114
|
+
| Command | Description |
|
|
115
|
+
|---------|-------------|
|
|
116
|
+
| `press <key>` | Press a key (Enter, ArrowDown, Tab, etc.) |
|
|
117
|
+
| `mousemove <x> <y>` | Move mouse to coordinates |
|
|
118
|
+
| `mousedown [button]` | Press mouse button |
|
|
119
|
+
| `mouseup [button]` | Release mouse button |
|
|
120
|
+
| `scroll <dx> <dy>` | Scroll the page |
|
|
121
|
+
|
|
122
|
+
### Tabs
|
|
123
|
+
|
|
124
|
+
| Command | Description |
|
|
125
|
+
|---------|-------------|
|
|
126
|
+
| `tab-list` | List all tabs |
|
|
127
|
+
| `tab-new [url]` | Create new tab |
|
|
128
|
+
| `tab-close [index]` | Close a tab |
|
|
129
|
+
| `tab-select <index>` | Select a tab |
|
|
130
|
+
|
|
131
|
+
### Cookies & Storage
|
|
132
|
+
|
|
133
|
+
| Command | Description |
|
|
134
|
+
|---------|-------------|
|
|
135
|
+
| `cookie-list [--domain=d]` | List cookies |
|
|
136
|
+
| `cookie-get <name>` | Get a cookie |
|
|
137
|
+
| `cookie-set <name> <val> [opts]` | Set a cookie |
|
|
138
|
+
| `cookie-delete <name>` | Delete a cookie |
|
|
139
|
+
| `cookie-clear` | Clear all cookies |
|
|
140
|
+
| `localstorage-list\|get\|set\|delete\|clear` | Manage localStorage |
|
|
141
|
+
| `sessionstorage-list\|get\|set\|delete\|clear` | Manage sessionStorage |
|
|
142
|
+
| `state-save [filename]` | Save cookies + storage to JSON |
|
|
143
|
+
| `state-load <filename>` | Restore cookies + storage from JSON |
|
|
144
|
+
|
|
145
|
+
### Session Management
|
|
146
|
+
|
|
147
|
+
| Command | Description |
|
|
148
|
+
|---------|-------------|
|
|
149
|
+
| `list` | List all active sessions |
|
|
150
|
+
| `close` | Close current session's browser |
|
|
151
|
+
| `close-all` | Close all sessions |
|
|
152
|
+
| `kill-all` | Kill all browser processes |
|
|
153
|
+
| `delete-data` | Delete user data for a session |
|
|
154
|
+
|
|
155
|
+
## Targeting Elements
|
|
156
|
+
|
|
157
|
+
DrissionPage supports rich locator syntax:
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
# CSS selector
|
|
161
|
+
drissionpage-cli click "css:#main > button.submit"
|
|
162
|
+
|
|
163
|
+
# XPath
|
|
164
|
+
drissionpage-cli click "xpath://button[@id='submit']"
|
|
165
|
+
|
|
166
|
+
# Text content
|
|
167
|
+
drissionpage-cli click "text:Submit"
|
|
168
|
+
|
|
169
|
+
# Tag name
|
|
170
|
+
drissionpage-cli click "tag:button"
|
|
171
|
+
|
|
172
|
+
# Attribute matching
|
|
173
|
+
drissionpage-cli click "@id=submit"
|
|
174
|
+
drissionpage-cli click "@class:btn" # contains
|
|
175
|
+
drissionpage-cli click "@name^=user" # starts with
|
|
176
|
+
drissionpage-cli click "@data-testid=login"
|
|
177
|
+
|
|
178
|
+
# Combined (AND)
|
|
179
|
+
drissionpage-cli click "@@tag()=button@@text()=Submit"
|
|
180
|
+
|
|
181
|
+
# Combined (OR)
|
|
182
|
+
drissionpage-cli click "@|id=btn1@id=btn2"
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
## Named Sessions
|
|
186
|
+
|
|
187
|
+
Run multiple isolated browser instances concurrently:
|
|
188
|
+
|
|
189
|
+
```bash
|
|
190
|
+
drissionpage-cli -s=auth open https://app.example.com/login
|
|
191
|
+
drissionpage-cli -s=scrape open https://data.example.com
|
|
192
|
+
drissionpage-cli list
|
|
193
|
+
drissionpage-cli close-all
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
Or set a default session via environment variable:
|
|
197
|
+
|
|
198
|
+
```bash
|
|
199
|
+
DRISSIONPAGE_CLI_SESSION=myproject drissionpage-cli open https://example.com
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
## Running Custom Code
|
|
203
|
+
|
|
204
|
+
Execute arbitrary DrissionPage Python code with `run-code`. The `page` variable is the active `ChromiumPage` instance. Set `result` to output a return value.
|
|
205
|
+
|
|
206
|
+
```bash
|
|
207
|
+
drissionpage-cli run-code "result = page.title"
|
|
208
|
+
drissionpage-cli run-code "
|
|
209
|
+
eles = page.eles('tag:a')
|
|
210
|
+
result = [{'text': a.text, 'href': a.link} for a in eles if a.link]
|
|
211
|
+
"
|
|
212
|
+
drissionpage-cli run-code --filename=myscript.py
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
## Testing
|
|
216
|
+
|
|
217
|
+
The project includes two test suites:
|
|
218
|
+
|
|
219
|
+
### Unit tests (no browser required)
|
|
220
|
+
|
|
221
|
+
92 tests covering the argument parser, session management, snapshot formatting, skill installation, state save/load, and all command handlers via mocks.
|
|
222
|
+
|
|
223
|
+
```bash
|
|
224
|
+
cd DrissionPage-cli
|
|
225
|
+
pip install pytest
|
|
226
|
+
python3 -m pytest tests/test_unit.py -v
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
### Integration tests (browser required)
|
|
230
|
+
|
|
231
|
+
30+ end-to-end tests that launch a real browser, navigate `data:` URLs, click elements, manage storage, take screenshots, etc.
|
|
232
|
+
|
|
233
|
+
```bash
|
|
234
|
+
python3 -m pytest tests/test_integration.py -v
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
To skip integration tests in CI (no browser available):
|
|
238
|
+
|
|
239
|
+
```bash
|
|
240
|
+
SKIP_INTEGRATION=1 python3 -m pytest tests/ -v
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
### Run all tests
|
|
244
|
+
|
|
245
|
+
```bash
|
|
246
|
+
python3 -m pytest tests/ -v
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
## Project Structure
|
|
250
|
+
|
|
251
|
+
```
|
|
252
|
+
DrissionPage-cli/
|
|
253
|
+
drissionpage_cli.py # Main CLI (40+ commands)
|
|
254
|
+
pyproject.toml # Python packaging
|
|
255
|
+
requirements.txt # DrissionPage>=4.0.0
|
|
256
|
+
pytest.ini # Test configuration
|
|
257
|
+
README.md
|
|
258
|
+
LICENSE
|
|
259
|
+
scripts/
|
|
260
|
+
update.py # Skill update script
|
|
261
|
+
skills/drissionpage-cli/
|
|
262
|
+
SKILL.md # Agent skill definition
|
|
263
|
+
references/
|
|
264
|
+
element-locators.md # CSS, XPath, text, attribute locators
|
|
265
|
+
running-code.md # run-code for custom automation
|
|
266
|
+
session-management.md # Multiple browser sessions
|
|
267
|
+
storage-state.md # Cookies, localStorage, sessionStorage
|
|
268
|
+
screenshots-pdf.md # Visual capture
|
|
269
|
+
network-listening.md # Network monitoring
|
|
270
|
+
dual-mode.md # Browser + HTTP requests mode
|
|
271
|
+
tests/
|
|
272
|
+
conftest.py # Shared fixtures
|
|
273
|
+
test_unit.py # 92 unit tests (mocked, no browser)
|
|
274
|
+
test_integration.py # 30+ integration tests (real browser)
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
## Environment Variables
|
|
278
|
+
|
|
279
|
+
| Variable | Description |
|
|
280
|
+
|----------|-------------|
|
|
281
|
+
| `DRISSIONPAGE_CLI_SESSION` | Default session name (default: `default`) |
|
|
282
|
+
| `DRISSIONPAGE_CLI_DIR` | CLI data directory (default: `.drissionpage-cli`) |
|
|
283
|
+
| `DRISSIONPAGE_CLI_DEBUG` | Set to `1` for full tracebacks on errors |
|
|
284
|
+
| `SKIP_INTEGRATION` | Set to `1` to skip browser integration tests |
|
|
285
|
+
|
|
286
|
+
## License
|
|
287
|
+
|
|
288
|
+
Apache-2.0
|