Skip to main content

Introduction

Selenium is a powerful tool for automating web browsers. This guide covers deploying Selenium scripts on Shard Cloud using Python.

Creating Your Project

Ensure you have Python and pip installed.

Installing Dependencies

Basic Selenium Script

Create a main.py file:
main.py

Requirements File

Create a requirements.txt:
requirements.txt
The Chrome options --no-sandbox and --disable-dev-shm-usage are required for Selenium to work in containerized environments.

Chrome/Chromium Path

On Shard Cloud, Chromium is installed at /usr/bin/chromium and ChromeDriver at /usr/bin/chromedriver. The WebDriver can locate these automatically.

Shard Cloud Configuration

Create a .shardcloud file:
.shardcloud
Selenium applications typically require at least 512MB-1024MB of memory due to the browser overhead.

Advanced Example: Web Scraping

scraper.py

Deploying

1

Prepare Your Files

Ensure you have: - main.py (or your script) - requirements.txt - .shardcloud
2

Exclude Unnecessary Files

Remove: __pycache__/, venv/, *.pyc
3

Create ZIP Archive

Compress your project folder.
4

Upload to Shard Cloud

Go to Shard Cloud Dashboard and upload.

Accessing Screenshots

Screenshots saved by your script can be downloaded from Shard Cloud’s file manager in the dashboard.

Additional Resources

Troubleshooting

  • Ensure you’re using headless mode - Add --disable-dev-shm-usage flag - Increase memory allocation
  • Use WebDriverWait for dynamic content - Verify the selector is correct - Take a screenshot to debug the page state
Close the driver after each task and increase the MEMORY value in your config.