Examples
Practical examples of using MCP Selenium Server
Examples
Practical examples demonstrating how to use the MCP Selenium Server for various automation tasks.
Docker Usage
Starting with Docker Compose
# Start the MCP server
docker compose up --build
# Run in background
docker compose up -d --build
# View logs
docker compose logs -f
# Stop the server
docker compose down
Testing Docker Installation
# Test MCP communication
echo '{"jsonrpc": "2.0", "id": 1, "method": "tools/list", "params": {}}' | docker exec -i <container_name> node dist/index.js
# Open a browser
echo '{"jsonrpc": "2.0", "id": 2, "method": "tools/call", "params": {"name": "open_browser", "arguments": {"browserId": "docker-test", "headless": true}}}' | docker exec -i <container_name> node dist/index.js
Docker Benefits
- No Local Dependencies: Chrome and ChromeDriver are included
- Consistent Environment: Same setup across different systems
- Easy Updates: Simple
docker compose pull
and restart - Isolation: No conflicts with local browser installations
Basic Browser Automation
Simple Navigation
{
"tool": "open_browser",
"arguments": {
"browserId": "example1",
"headless": false
}
}
{
"tool": "navigate_to",
"arguments": {
"url": "https://example.com",
"browserId": "example1"
}
}
{
"tool": "get_page_title",
"arguments": {
"browserId": "example1"
}
}
Form Interaction
{
"tool": "type_text",
"arguments": {
"selector": "#username",
"text": "myusername",
"browserId": "example1"
}
}
{
"tool": "type_text",
"arguments": {
"selector": "#password",
"text": "mypassword",
"browserId": "example1"
}
}
{
"tool": "click_element",
"arguments": {
"selector": "#login-button",
"browserId": "example1"
}
}
Multi-Browser Scenarios
User Session Management
{
"tool": "open_browser",
"arguments": {
"browserId": "user1",
"headless": false
}
}
{
"tool": "open_browser",
"arguments": {
"browserId": "user2",
"headless": false
}
}
{
"tool": "navigate_to",
"arguments": {
"url": "https://app.example.com",
"browserId": "user1"
}
}
{
"tool": "navigate_to",
"arguments": {
"url": "https://app.example.com",
"browserId": "user2"
}
}
Parallel Testing
{
"tool": "list_browsers",
"arguments": {}
}
Advanced Operations
Screenshot Capture
{
"tool": "take_screenshot",
"arguments": {
"filename": "page-screenshot.png",
"fullPage": true,
"browserId": "example1"
}
}
JavaScript Execution
{
"tool": "execute_script",
"arguments": {
"script": "return document.title;",
"browserId": "example1"
}
}
Action Sequences
{
"tool": "execute_action_sequence",
"arguments": {
"actions": [
{
"action": "navigate_to",
"value": "https://example.com"
},
{
"action": "click",
"selector": "#button1"
},
{
"action": "type",
"selector": "#input1",
"text": "Hello World"
}
],
"browserId": "example1"
}
}
Drag and Drop
{
"tool": "drag_and_drop",
"arguments": {
"sourceSelector": "#draggable-item",
"targetSelector": "#drop-zone",
"browserId": "example1"
}
}
Console Monitoring
Capture Console Logs
{
"tool": "get_console_logs",
"arguments": {
"level": "error",
"limit": 10,
"browserId": "example1"
}
}
Clear Console
{
"tool": "clear_console_logs",
"arguments": {
"browserId": "example1"
}
}
Error Handling
Check Browser Status
{
"tool": "get_browser_info",
"arguments": {
"browserId": "example1"
}
}
List Active Browsers
{
"tool": "list_browsers",
"arguments": {}
}
Close Specific Browser
{
"tool": "close_browser",
"arguments": {
"browserId": "example1"
}
}
Real-World Use Cases
Web Scraping
- Open browser with custom ID
- Navigate to target website
- Extract data using JavaScript execution
- Take screenshots for verification
- Close browser when done
Automated Testing
- Open multiple browser instances for different test scenarios
- Run parallel tests across different browsers
- Capture screenshots and console logs for debugging
- Clean up all browser instances after testing
User Journey Simulation
- Open browser for each user persona
- Navigate through different user flows
- Interact with forms and buttons
- Monitor console for errors
- Generate reports with screenshots
Performance Monitoring
- Open browser and navigate to application
- Execute performance measurement scripts
- Capture console logs for analysis
- Take screenshots at key points
- Generate performance reports