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 installed on your machine. You can download the latest version of Python at python.org.
Folder setup
mkdir test-project
cd test-project
Create virtual environment
#Windows
python -m venv .venv
#Linux
python3 -m venv .venv
Access virtual environment
#Windows
.venv\Scripts\activate
#Linux
source .venv\bin\activate
Dependencies Installation
#Windows
pip install selenium
#Linux
pip3 install selenium
Script 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.txt
linux
pip3 freeze >> requirements.txt
Publication
Follow the instructions in the Publish Bot section to publish your project in .zip
format.
Last updated on