Automating Web Actions with Python and Selenium: Streamline Your Workflows

In this guide, we will focus on web automation using Python and Selenium, using OrangeHRM as our testing website. Our goal is to automate tasks like logging in, modifying a field, and verifying the amendment is successful. By harnessing the power of Python and Selenium, we'll streamline these actions and uncover the efficiency of web automation. Let's get started and embark on this journey of automation!

Step 1: Setting up the Environment

To ensure you have Python 3 and Selenium installed on your system, follow the steps below:

  1. Open your command prompt or terminal.
  2. Check if Selenium is installed by running the command:
pip3 list | grep selenium
  • If Selenium is installed, you will see its version and related packages listed.
  • If not installed, you can install it using the command: pip3 install selenium.
  1. Verify your Python version by running the command:
python3 --version
  • This command will display the installed Python version. Ensure it is Python 3.x (e.g., 3.7, 3.8, 3.9).

By performing these steps, you can confirm that both Python 3 and Selenium are installed on your system. This verification is essential before proceeding with web automation using Python and Selenium.

Step 2: Testing the Script

Copy the following Python script and run it to test the script. This script will perform a series of actions, showcasing the automation capabilities

from selenium import webdriver
from import By
from selenium.webdriver.common.keys import Keys
import random
import time

# Initialize ChromeDriver
driver = webdriver.Chrome()

# Navigate to the OrangeHRM login page

# Find and enter the Username
driver.find_element(By.NAME, 'username').send_keys('Admin')

# Find and enter the Password
driver.find_element(By.NAME, 'password').send_keys('admin123')

# Click the Login button
driver.find_element(By.TAG_NAME, "button").click()

# Extract information from the page before making changes
text = driver.find_element(By.CLASS_NAME, 'oxd-userdropdown-name').text
print("Username (Before): " + text)

# Go to the My Info page
driver.find_element(By.LINK_TEXT, 'My Info').click()

# Generate a random word to replace the Lastname
word_file = "/usr/share/dict/words"
WORDS = open(word_file).read().splitlines()
word = random.choice(WORDS)

# Replace the Lastname field with the generated word
lastName = driver.find_element(By.NAME, 'lastName')
lastName.send_keys(Keys.COMMAND + "a")

# Click the Save Button
driver.find_element(By.XPATH, '//button[text()=" Save "]').click()

# Refresh the page

# Extract information from the page after making changes
text = driver.find_element(By.CLASS_NAME, 'oxd-userdropdown-name').text
print("Username (After): " + text)

# Close the browser

Once you execute the script, you will observe the browser window launching, the automation actions being performed, and the output displaying the username before and after the changes made.


Congratulations! You have successfully executed the script, automating web actions using Python and Selenium. This script demonstrates the power of automation by logging into OrangeHRM, updating information, and extracting data from the web page. Feel free to explore and modify the script to suit your specific automation needs.

Note: Please ensure that you have a stable internet connection and that the OrangeHRM website is accessible while executing the script. It is important to note that OrangeHRM is the property of its rightful owner, and this script is solely for educational and demonstration purposes. If there are any concerns regarding copyright or other related matters, please reach out via email at [].