> ## Documentation Index
> Fetch the complete documentation index at: https://docs.squarecloud.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Run Selenium with Headless Chromium

> Selenium automation on Square Cloud: run a Python script with headless Chromium and ChromeDriver, the flags containers need, requirements.txt and deploy.

## Professional Selenium script development

To implement efficient web automation on Square Cloud, it's essential to establish a proper development environment and follow configuration best practices.

### Essential technical prerequisites

* **Python and pip**: Make sure you have **Python** and **pip** installed on your system. If you don't have them, download from the [official Python website](https://www.python.org/) and the [official Pip website](https://pypi.org/).
* **Square Cloud Account**: Create your account through the [signup page](https://squarecloud.app/en/signup), using your email address for registration.
* **Active plan**: An active plan is necessary to ensure adequate resources for running Selenium applications. Check our [available plans](https://squarecloud.app/en/pricing) and choose the most suitable for your needs.

### Selenium environment configuration

With Python and pip installed, proceed with creating the Selenium script. First, install the Selenium library:

```bash Terminal theme={"system"}
pip install selenium
```

Next, create a Python file (for example, `main.py`) and add the following code to implement a basic Selenium script:

```python main.py theme={"system"}
import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service

# Configuration options for Chromium
options = Options()
options.add_argument("--headless")  # Runs in background without graphical interface
options.add_argument("--no-sandbox")  # Required in containers, where the Chromium sandbox can't start
options.add_argument("--disable-dev-shm-usage")  # Overcomes shared memory limitations on large pages

# Driver initialization
service = Service('/usr/bin/chromedriver')  # Default ChromeDriver path on Square Cloud
driver = webdriver.Chrome(service=service, options=options)

# Browser window dimensions configuration
driver.set_window_size(1920, 1080)  # Adjust as needed for your application

# Navigate to web page
driver.get('https://www.google.com')

# Loop for screenshot capture every minute
while True:
    driver.save_screenshot('page.png')
    print("Page screenshot saved successfully.")
    time.sleep(60)  # 60-second pause between captures
```

## Dependency management with requirements.txt

The `requirements.txt` file is an essential component that lists all external libraries needed for your project. It's crucial to include all dependencies used, excluding native Python libraries like `random` and `datetime`. This file should be included when submitting your application to Square Cloud.

```txt requirements.txt theme={"system"}
selenium
```

## Chromium path configuration

In the implementation presented above, it's not necessary to explicitly define the Chromium path, as the Selenium WebDriver can automatically locate the browser when installed in a standard system location. The ChromeDriver, specified with `Service('/usr/bin/chromedriver')`, has knowledge about where to locate the Chromium/Chrome executable.

### Square Cloud architecture

On Square Cloud, Chromium is installed at `/usr/bin/chromium`, which is the standard system location. Therefore, the Selenium WebDriver can locate it automatically through the specified ChromeDriver. Thus, there's no need to explicitly specify the Chromium path in the code, unless there are specific reasons to do so, such as custom installations or different environment configurations.

## Square Cloud configuration file

Create a `squarecloud.app` file at the root of your project, next to `main.py`. It tells Square Cloud how to run your script:

```systemd squarecloud.app theme={"system"}
DISPLAY_NAME=Selenium Automation
MAIN=main.py
MEMORY=1024
VERSION=recommended
AUTORESTART=true
```

* `MEMORY` is the RAM in MB. Chromium is memory hungry, so give it at least 1024 MB and raise it if the application stops with `LACK_OF_RAM`.
* `AUTORESTART=true` starts the script again if it crashes. See [how auto restart works](https://help.squarecloud.app/en-us/article/how-to-use-auto-restart-on-square-cloud-nmhvh0/).
* There is no `SUBDOMAIN`: the script doesn't serve web pages.

Your ZIP holds `main.py`, `requirements.txt` and `squarecloud.app`.

<Card title="Learn about: how to create the configuration file for Square Cloud." icon="link" href="/en/getting-started/config-file">
  The squarecloud.app file is an essential configuration file that will be used to configure your application on Square Cloud. It defines name, description, version, main file, among other fundamental configurations.
</Card>

## Project upload to Square Cloud

After preparing all project files, proceed with uploading to Square Cloud and host your application professionally.

### Via dashboard

<Steps>
  <Step title="Access the Upload Page">
    Access the [upload page](https://squarecloud.app/en/dashboard/new) and upload your project zip file.
  </Step>

  <Step title="Configure Your Environment">
    After uploading your zip, you will need to configure the name, main file or runtime environment and other settings for your project.\
    If you are uploading a web project, make sure to select "Web Publication" and set a subdomain to your project.
  </Step>

  <Step title="Deploy Your Project">
    Finally, click on the "Deploy" button to host your project on Square Cloud.\
    After deployment, you can monitor your project's status and logs from the dashboard.

    <Frame>
      <img src="https://cdn.squarecloud.app/docs/articles/dashboard/uploading.gif" alt="Uploading application to Square Cloud" style={{ borderRadius: "0.2rem" }} />
    </Frame>
  </Step>

  <Step title="Confirm Your App Is Live">
    Your first deploy usually takes less than a minute. In the [dashboard](https://squarecloud.app/en/dashboard), wait for your application status to show as running and check the logs for any startup errors.\
    If you deployed a website or API, open `https://<your-subdomain>.squareweb.app` in your browser: you should see your application responding. If you deployed a bot, send it a command to confirm it is online.
    <Tip>App not starting? See the [Troubleshooting guide](/en/platform/troubleshooting/app-wont-start) for the most common causes and fixes.</Tip>
  </Step>
</Steps>

### Via CLI

To use this method, your project needs a configuration file named `squarecloud.app` at its root. It tells Square Cloud how to run your application.

<Card title="Configuration file guide" icon="link" href="/en/getting-started/config-file">
  Learn how to create the `squarecloud.app` configuration file that defines your application's environment.
</Card>

<Steps>
  <Step title="Install the CLI">
    Install the [Square Cloud CLI](/en/cli-reference/installation). If you already have it, run the same command to update it:

    <CodeGroup>
      ```bash macOS, Linux, and WSL theme={"system"}
      curl -fsSL https://cli.squarecloud.app/install | bash
      ```

      ```bash Windows with npm theme={"system"}
      npm install -g @squarecloud/cli@latest
      ```
    </CodeGroup>
  </Step>

  <Step title="Log In">
    Run the command below. It opens your browser: approve the login there and the CLI is ready. There is no API key to copy. For scripts and CI, see [CLI authentication](/en/cli-reference/authentication).

    ```bash theme={"system"}
    squarecloud auth login
    ```
  </Step>

  <Step title="Upload Your Project">
    From your project folder, run the command below. The CLI zips the current folder, leaving out what [`squarecloud.ignore`](/en/getting-started/squarecloud-ignore) lists, and uploads it:

    ```bash theme={"system"}
    squarecloud upload
    ```

    To upload a zip you created yourself, pass it with `--file`:

    ```bash theme={"system"}
    squarecloud upload --file <path/to/zip>
    ```
  </Step>

  <Step title="Confirm Your App Is Live">
    Your first deploy usually takes less than a minute. Check your application status and logs directly from the terminal:

    ```bash theme={"system"}
    squarecloud app status
    squarecloud app logs
    ```

    If you deployed a website or API, open `https://<your-subdomain>.squareweb.app` in your browser: you should see your application responding. If you deployed a bot, send it a command to confirm it is online.
    <Tip>App not starting? See the [Troubleshooting guide](/en/platform/troubleshooting/app-wont-start) for the most common causes and fixes.</Tip>
  </Step>
</Steps>

## Additional resources and documentation

For more detailed information about Selenium and its advanced tools, visit the [official Selenium documentation](https://www.selenium.dev/documentation/webdriver/getting_started/). There you'll find detailed technical guides, specialized tutorials, and complete API documentation to maximize the use of Selenium functionalities.

## Next steps

<CardGroup cols={3}>
  <Card title="App won't start" icon="triangle-exclamation" href="/en/platform/troubleshooting/app-wont-start">
    Fix LACK\_OF\_RAM, missing modules and other startup failures.
  </Card>

  <Card title="Python runtime" icon="python" href="/en/articles/getting-started-with-python">
    How Square Cloud runs Python applications.
  </Card>

  <Card title="Environment variables" icon="key" href="/en/platform/environment-variables">
    Keep logins and API keys used by your automation out of your code.
  </Card>
</CardGroup>

## Contact us

If you continue facing **technical difficulties**, our **specialized support team** is available to assist you. [**Contact us**](https://squarecloud.app/en/support) and we'll be happy to help you resolve any issue: support quality is a big part of why developers rate Square Cloud [**4.9/5 across 402 reviews**](https://www.trustpilot.com/review/squarecloud.app) on Google and Trustpilot.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.