Automates file uploads to web pages using agent-browser CLI.
Upload a file to a web page:
bash
# Basic upload (auto-detects file input)
agent-browser open <url>
agent-browser find text 选择文件 click
agent-browser upload "#filePicker" <file-path>
# Or use the Python script
python scripts/upload_file.py <url> <file-path>
When you know the file input selector:
bash
agent-browser open https://example.com/upload
agent-browser click "#fileInput"
agent-browser upload "#fileInput" C:\path\to\file.xlsx
When file input has visible label text:
bash
agent-browser open https://example.com/upload
agent-browser find text "上传文件" click
agent-browser upload "[type=file]" C:\path\to\file.xlsx
For reusable upload logic with flexible path specification:
bash
python scripts/upload_file.py <url> <file-path> [selector] [wait_ms]
Arguments:
url - Target page URLfile-path - Path to file (supports multiple formats, see below)selector - Optional CSS selector for file inputwait_ms - Optional wait time after page load (default: 2000)The Python script supports multiple path formats:
FormatExampleDescriptionAbsoluteC:\Users\name\file.xlsxFull pathRelative./data/file.xlsxRelative to current directoryWorkspaceworkspace/file.xlsxRelative to OPENCLAW_WORKSPACEEnv Var${HOME}/file.xlsxEnvironment variableWindows Env%USERPROFILE%\file.xlsxWindows environment variable
bash
# Absolute path
python scripts/upload_file.py https://example.com C:\Users\陈\Documents\data.xlsx
# Relative path (from workspace)
python scripts/upload_file.py https://example.com ./test.xlsx
# Workspace-relative
python scripts/upload_file.py https://example.com workspace/data/test.xlsx
# With environment variable
python scripts/upload_file.py https://example.com ${HOME}/downloads/file.xlsx
SelectorDescription#filePickerCommon id for file inputs[type=file]Any file input elementinput[type=file]Explicit file input.upload-zoneDrop zone containers
File input not found:
agent-browser snapshot to inspect page elements[type=file] or file-related buttonsUpload fails:
test-path <file-path>agent-browser find text 选择文件 click firstPage not loaded:
agent-browser wait 2000 after openagent-browser wait --load networkidle for slow pagesbash
# Inspect page elements
agent-browser snapshot
# Take screenshot
agent-browser screenshot
# Find elements by text
agent-browser find text "上传"
# Click element
agent-browser click <selector>
# Upload file
agent-browser upload <selector> <file-path>
bash
# Method 1: Direct agent-browser commands
agent-browser open https://uutool.cn/excel/
agent-browser wait 2000
agent-browser find text 选择文件 click
agent-browser upload "#filePicker" C:\Users\陈\.openclaw\workspace\test.xlsx
# Method 2: Using Python script with absolute path
python scripts/upload_file.py https://uutool.cn/excel/ C:\Users\陈\.openclaw\workspace\test.xlsx
# Method 3: Using Python script with workspace-relative path
python scripts/upload_file.py https://uutool.cn/excel/ workspace/test.xlsx
# Method 4: Using Python script with custom selector and wait time
python scripts/upload_file.py https://uutool.cn/excel/ workspace/test.xlsx "#filePicker" 3000