Published on: 27 Oct, 2021
Updated on: 30 Oct, 2021
Getting started with Our Very First Automation Script Using Python & Selenium
Here we will be exploring about the very first automation script using Selenium and Python
As we all know, today automation testing is increasing exponentially and ruling the IT world. Today, every organization some or other way moving towards automation and that leads to an increase in demand for automation tools in the IT market. And one of such tools that have gained enormous popularity among the automation tester community is Selenium.
Selenium is rapidly emerging as one of the most widely used test automation tools. Gartner also reports that Selenium being an open-source automated testing tool has a high adoption rate.
Selenium was developed in 2004, by Jason Huggins, while testing an inside application (Time and Expenses (T&E) framework) at Thought Works.
Basically, selenium comes in 4 major flavors such as:
- Selenium IDE (Integrated Development Environment)
- Selenium RC (Remote Control) - DEPRECATED
- Selenium Webdriver
- Selenium Grid
But, here we will be mostly focusing on the Selenium web driver which is one of the most used and popular automation tools in IT industries.
So let get dive into setting up the selenium web driver on our system and write our very first automation script using Python.
Setting up Selenium on Windows/Mac/Linux
- Open terminal/CMD on your system and create a "Python virtual environment"
- To create a python virtual environment, please refer - Setting up Python environment on your system
- Once we are done with virtual env setup, activate the virtual environment using:
For windows user
\env\Scripts\activate.bat
For mac/Linux user
source \env\bin\activate
- After activating virtual env, just cross-check whether you have expected Python
version installed or not using-
python --version
- Now, its time to install selenium and to do so we need to execute below command
👉NOTE: We can directly install selenium at the system level but that's really not a good practice and also it may impact the existing project which is using the instance of python installed at the system level
pip install selenium
Downloading chromedriver for Windows/Mac/Linux
- Go to Selenium official website - https://www.selenium.dev/
- Download the respective browser driver from - .Here, we will be working with chorme browser since we will be downloading
chromedriver
- Extract the downloaded driver zip file and place the executable file
chromedriver.exe
(for Windows) & binarychromedriver
(for Mac/Linux) file at your desired location from extracted zip folder
Writing our first Selenium automation script using Python
- Open any of the text editor "Sublime Text/ Atom/ VS Code"
- Open new file & add below line of code to it and save it with extension
.py
from selenium import webdriver
driver = webdriver.Chrome("path_to_chromedriver")
driver.url("https://selenium.dev")
python filename.py
👉NOTE: Make sure whatever set up we have done so far should be within virtual environment
Here are similar posts
We have more silimar posts that you would love to checkout