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 and the official Pip website.
  • Square Cloud Account: Create your account through the signup page, using your email address for registration.
  • Active Paid Plan: A paid plan is necessary to ensure adequate resources for running Selenium applications. Check our available plans 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:
Terminal
pip install selenium
Next, create a Python file (for example, main.py) and add the following code to implement a basic Selenium script:
main.py
import time
from selenium import webdriver
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 for execution as root in containerized environments
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.
requirements.txt
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

Learn about: how to create the configuration file for Square Cloud.

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.

Project Upload to Square Cloud

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

Additional Resources and Documentation

For more detailed information about Selenium and its advanced tools, visit the official Selenium documentation. There you’ll find detailed technical guides, specialized tutorials, and complete API documentation to maximize the use of Selenium functionalities. If you continue facing technical difficulties, our specialized support team is available to assist you. Contact us and we'll be happy to help you resolve any issue.