Python
This page presents a simple automation example using Python and Selenium.
main.py: main script that will be executed.requirements.txt: project dependencies list.
Code Example
Note
Make sure you have Python 3.12 or higher installed on your machine. You can download the latest version of Python at python.org.
Folder setup
mkdir test-project
cd test-projectCreate virtual environment
#Windows
python -m venv .venv
#Linux
python3 -m venv .venvAccess virtual environment
#Windows
.venv\Scripts\activate
#Linux
source .venv\bin\activateDependencies Installation
#Windows
pip install selenium
#Linux
pip3 install seleniumScript Creation
The script below opens the browser, accesses Google, waits 3 seconds, and closes the browser.
bot.py
from selenium import webdriver
import time
# Start the browser
driver = webdriver.Chrome()
# Access Google
driver.get('https://www.google.com')
# Wait 3 seconds
time.sleep(3)
# Close the browser
driver.quit()Generate dependencies file
To ensure that all project dependencies are installed correctly in another environment, generate the requirements.txt file with the command below:
windows
pip freeze >> requirements.txtlinux
pip3 freeze >> requirements.txtPublication
Follow the instructions in the Publish Bot section to publish your project in .zip format.
Last updated on