docs/md_v2/api/c4a-script-reference.md
Complete reference for all C4A-Script commands, syntax, and advanced features.
Navigate between pages and manage browser history.
GO <url>Navigate to a specific URL.
Syntax:
GO <url>
Parameters:
url - Target URL (string)Examples:
GO https://example.com
GO https://api.example.com/login
GO /relative/path
Notes:
RELOADRefresh the current page.
Syntax:
RELOAD
Examples:
RELOAD
Notes:
BACKNavigate back in browser history.
Syntax:
BACK
Examples:
BACK
Notes:
FORWARDNavigate forward in browser history.
Syntax:
FORWARD
Examples:
FORWARD
Notes:
Control timing and synchronization with page elements.
WAIT <time>Wait for a specified number of seconds.
Syntax:
WAIT <seconds>
Parameters:
seconds - Number of seconds to wait (number)Examples:
WAIT 3
WAIT 1.5
WAIT 10
Notes:
WAIT <selector> <timeout>Wait for an element to appear on the page.
Syntax:
WAIT `<selector>` <timeout>
Parameters:
selector - CSS selector for the element (string in backticks)timeout - Maximum seconds to wait (number)Examples:
WAIT `#content` 10
WAIT `.loading-spinner` 5
WAIT `button[type="submit"]` 15
WAIT `.results .item:first-child` 8
Notes:
WAIT "<text>" <timeout>Wait for specific text to appear anywhere on the page.
Syntax:
WAIT "<text>" <timeout>
Parameters:
text - Text content to wait for (string in quotes)timeout - Maximum seconds to wait (number)Examples:
WAIT "Loading complete" 10
WAIT "Welcome back" 5
WAIT "Search results" 15
Notes:
Simulate mouse interactions and movements.
CLICK <selector>Click on an element specified by CSS selector.
Syntax:
CLICK `<selector>`
Parameters:
selector - CSS selector for the element (string in backticks)Examples:
CLICK `#submit-button`
CLICK `.menu-item:first-child`
CLICK `button[data-action="save"]`
CLICK `a[href="/dashboard"]`
Notes:
CLICK <x> <y>Click at specific coordinates on the page.
Syntax:
CLICK <x> <y>
Parameters:
x - X coordinate in pixels (number)y - Y coordinate in pixels (number)Examples:
CLICK 100 200
CLICK 500 300
CLICK 0 0
Notes:
DOUBLE_CLICK <selector>Double-click on an element.
Syntax:
DOUBLE_CLICK `<selector>`
Parameters:
selector - CSS selector for the element (string in backticks)Examples:
DOUBLE_CLICK `.file-icon`
DOUBLE_CLICK `#editable-cell`
DOUBLE_CLICK `.expandable-item`
Notes:
RIGHT_CLICK <selector>Right-click on an element to open context menu.
Syntax:
RIGHT_CLICK `<selector>`
Parameters:
selector - CSS selector for the element (string in backticks)Examples:
RIGHT_CLICK `#context-target`
RIGHT_CLICK `.menu-trigger`
RIGHT_CLICK `img.thumbnail`
Notes:
SCROLL <direction> <amount>Scroll the page in a specified direction.
Syntax:
SCROLL <direction> <amount>
Parameters:
direction - Direction to scroll: UP, DOWN, LEFT, RIGHTamount - Number of pixels to scroll (number)Examples:
SCROLL DOWN 500
SCROLL UP 200
SCROLL LEFT 100
SCROLL RIGHT 300
Notes:
MOVE <x> <y>Move mouse cursor to specific coordinates.
Syntax:
MOVE <x> <y>
Parameters:
x - X coordinate in pixels (number)y - Y coordinate in pixels (number)Examples:
MOVE 200 100
MOVE 500 400
Notes:
DRAG <x1> <y1> <x2> <y2>Drag from one point to another.
Syntax:
DRAG <x1> <y1> <x2> <y2>
Parameters:
x1, y1 - Starting coordinates (numbers)x2, y2 - Ending coordinates (numbers)Examples:
DRAG 100 100 500 300
DRAG 0 200 400 200
Notes:
Simulate keyboard input and key presses.
TYPE "<text>"Type text into the currently focused element.
Syntax:
TYPE "<text>"
Parameters:
text - Text to type (string in quotes)Examples:
TYPE "Hello, World!"
TYPE "[email protected]"
TYPE "Password123!"
Notes:
TYPE $<variable>Type the value of a variable.
Syntax:
TYPE $<variable>
Parameters:
variable - Variable name (without quotes)Examples:
SETVAR email = "[email protected]"
TYPE $email
Notes:
PRESS <key>Press and release a special key.
Syntax:
PRESS <key>
Parameters:
key - Key name (see supported keys below)Supported Keys:
Tab, Enter, Escape, SpaceArrowUp, ArrowDown, ArrowLeft, ArrowRightDelete, BackspaceHome, End, PageUp, PageDownExamples:
PRESS Tab
PRESS Enter
PRESS Escape
PRESS ArrowDown
Notes:
KEY_DOWN <key>Hold down a modifier key.
Syntax:
KEY_DOWN <key>
Parameters:
key - Modifier key: Shift, Control, Alt, MetaExamples:
KEY_DOWN Shift
KEY_DOWN Control
Notes:
KEY_UP <key>Release a modifier key.
Syntax:
KEY_UP <key>
Parameters:
key - Modifier key: Shift, Control, Alt, MetaExamples:
KEY_UP Shift
KEY_UP Control
Notes:
CLEAR <selector>Clear the content of an input field.
Syntax:
CLEAR `<selector>`
Parameters:
selector - CSS selector for input element (string in backticks)Examples:
CLEAR `#search-box`
CLEAR `input[name="email"]`
CLEAR `.form-input:first-child`
Notes:
SET <selector> "<value>"Set the value of an input field directly.
Syntax:
SET `<selector>` "<value>"
Parameters:
selector - CSS selector for input element (string in backticks)value - Value to set (string in quotes)Examples:
SET `#email` "[email protected]"
SET `#age` "25"
SET `textarea#message` "Hello, this is a test message."
Notes:
Add conditional logic and loops to your scripts.
IF (EXISTS <selector>) THEN <command>Execute command if element exists.
Syntax:
IF (EXISTS `<selector>`) THEN <command>
Parameters:
selector - CSS selector to check (string in backticks)command - Command to execute if condition is trueExamples:
IF (EXISTS `.cookie-banner`) THEN CLICK `.accept-cookies`
IF (EXISTS `#popup-modal`) THEN CLICK `.close-button`
IF (EXISTS `.error-message`) THEN RELOAD
Notes:
IF (EXISTS <selector>) THEN <command> ELSE <command>Execute command based on element existence.
Syntax:
IF (EXISTS `<selector>`) THEN <command> ELSE <command>
Parameters:
selector - CSS selector to check (string in backticks)command - Execute if condition is truecommand - Execute if condition is falseExamples:
IF (EXISTS `.user-menu`) THEN CLICK `.logout` ELSE CLICK `.login`
IF (EXISTS `.loading`) THEN WAIT 5 ELSE CLICK `#continue`
Notes:
IF (NOT EXISTS <selector>) THEN <command>Execute command if element does not exist.
Syntax:
IF (NOT EXISTS `<selector>`) THEN <command>
Parameters:
selector - CSS selector to check (string in backticks)command - Command to execute if element doesn't existExamples:
IF (NOT EXISTS `.logged-in`) THEN GO /login
IF (NOT EXISTS `.results`) THEN CLICK `#search-button`
Notes:
IF (<javascript>) THEN <command>Execute command based on JavaScript condition.
Syntax:
IF (`<javascript>`) THEN <command>
Parameters:
javascript - JavaScript expression that returns boolean (string in backticks)command - Command to execute if condition is trueExamples:
IF (`window.innerWidth < 768`) THEN CLICK `.mobile-menu`
IF (`document.readyState === "complete"`) THEN CLICK `#start`
IF (`localStorage.getItem("user")`) THEN GO /dashboard
Notes:
REPEAT (<command>, <count>)Repeat a command a specific number of times.
Syntax:
REPEAT (<command>, <count>)
Parameters:
command - Command to repeatcount - Number of times to repeat (number)Examples:
REPEAT (SCROLL DOWN 300, 5)
REPEAT (PRESS Tab, 3)
REPEAT (CLICK `.load-more`, 10)
Notes:
REPEAT (<command>, <condition>)Repeat a command while condition is true.
Syntax:
REPEAT (<command>, `<condition>`)
Parameters:
command - Command to repeatcondition - JavaScript condition to check (string in backticks)Examples:
REPEAT (SCROLL DOWN 500, `document.querySelector(".load-more")`)
REPEAT (PRESS ArrowDown, `window.scrollY < document.body.scrollHeight`)
Notes:
Store and manipulate data within scripts.
SETVAR <name> = "<value>"Create or update a variable.
Syntax:
SETVAR <name> = "<value>"
Parameters:
name - Variable name (alphanumeric, underscore)value - Variable value (string in quotes)Examples:
SETVAR username = "[email protected]"
SETVAR password = "secret123"
SETVAR base_url = "https://api.example.com"
SETVAR counter = "0"
Notes:
EVAL <javascript>Execute arbitrary JavaScript code.
Syntax:
EVAL `<javascript>`
Parameters:
javascript - JavaScript code to execute (string in backticks)Examples:
EVAL `console.log("Script started")`
EVAL `window.scrollTo(0, 0)`
EVAL `localStorage.setItem("test", "value")`
EVAL `document.title = "Automated Test"`
Notes:
# <comment>Add comments to scripts for documentation.
Syntax:
# <comment text>
Examples:
# This script logs into the application
# Step 1: Navigate to login page
GO /login
# Step 2: Fill credentials
TYPE "[email protected]"
Notes:
Define reusable command sequences.
PROC <name> ... ENDPROCDefine a reusable procedure.
Syntax:
PROC <name>
<commands>
ENDPROC
Parameters:
name - Procedure name (alphanumeric, underscore)commands - Commands to include in procedureExamples:
PROC login
CLICK `#email`
TYPE $email
CLICK `#password`
TYPE $password
CLICK `#submit`
ENDPROC
PROC handle_popups
IF (EXISTS `.cookie-banner`) THEN CLICK `.accept`
IF (EXISTS `.newsletter-modal`) THEN CLICK `.close`
ENDPROC
Notes:
<procedure_name>Call a defined procedure.
Syntax:
<procedure_name>
Examples:
# Define procedure first
PROC setup
GO /login
WAIT `#form` 5
ENDPROC
# Call procedure
setup
login
Notes:
# Bad - element might not be ready
CLICK `#button`
# Good - wait for element first
WAIT `#button` 5
CLICK `#button`
# Check before interacting
IF (EXISTS `.popup`) THEN CLICK `.close`
IF (EXISTS `.cookie-banner`) THEN CLICK `.accept`
# Then proceed with main flow
CLICK `#main-action`
# Set up reusable data
SETVAR admin_email = "[email protected]"
SETVAR test_password = "TestPass123!"
SETVAR staging_url = "https://staging.example.com"
# Use throughout script
GO $staging_url
TYPE $admin_email
# Log progress
EVAL `console.log("Starting login process")`
GO /login
# Verify page state
IF (`document.title.includes("Login")`) THEN EVAL `console.log("On login page")`
# Continue with login
TYPE $username
# Complete login automation
SETVAR email = "[email protected]"
SETVAR password = "mypassword"
GO /login
WAIT `#login-form` 5
# Handle optional cookie banner
IF (EXISTS `.cookie-banner`) THEN CLICK `.accept-cookies`
# Fill and submit form
CLICK `#email`
TYPE $email
PRESS Tab
TYPE $password
CLICK `button[type="submit"]`
# Wait for redirect
WAIT `.dashboard` 10
# Load all content with infinite scroll
GO /products
# Scroll and load more content
REPEAT (SCROLL DOWN 500, `document.querySelector(".load-more")`)
# Alternative: Fixed number of scrolls
REPEAT (SCROLL DOWN 800, 10)
WAIT 2
# Handle form with validation
SET `#email` "invalid-email"
CLICK `#submit`
# Check for validation error
IF (EXISTS `.error-email`) THEN SET `#email` "[email protected]"
# Retry submission
CLICK `#submit`
WAIT `.success-message` 5
# Complex multi-step workflow
PROC navigate_to_step
CLICK `.next-button`
WAIT `.step-content` 5
ENDPROC
# Step 1
WAIT `.step-1` 5
SET `#name` "John Doe"
navigate_to_step
# Step 2
SET `#email` "[email protected]"
navigate_to_step
# Step 3
CLICK `#submit-final`
WAIT `.confirmation` 10
Use C4A-Script with Crawl4AI for dynamic content interaction:
from crawl4ai import AsyncWebCrawler, CrawlerRunConfig
# Define interaction script
script = """
# Handle dynamic content loading
WAIT `.content` 5
IF (EXISTS `.load-more-button`) THEN CLICK `.load-more-button`
WAIT `.additional-content` 5
# Accept cookies if needed
IF (EXISTS `.cookie-banner`) THEN CLICK `.accept-all`
"""
config = CrawlerRunConfig(
c4a_script=script,
wait_for=".content",
screenshot=True
)
async with AsyncWebCrawler() as crawler:
result = await crawler.arun("https://example.com", config=config)
print(result.markdown)
This reference covers all available C4A-Script commands and patterns. For interactive learning, try the tutorial or live demo.