Selenium is one such tool that allows you to run automated tests on web applications. One notable component of the complete Selenium package is the Selenium WebDriver. In this article, we will provide a brief introduction to Selenium, along with a detailed guide on how you can install and setup Selenium WebDriver on your system.

What Is Selenium

Selenium is an open source automation testing framework that is primarily used to validate web apps on different browsers and platforms. The framework is available for a number of programming languages including Java, C#, Python, and Perl.

There are various components of the Selenium framework:

Selenium IDE (Integrated Development Environment) Selenium Remote Control Selenium WebDriver Selenium Grid

All of these components have some distinct features associated with them. But in general, the whole Selenium framework helps in the automated testing of web applications.

In addition to web testing, you can develop web crawlers using the Selenium WebDriver as well.

Installing Selenium WebDriver

To install Selenium WebDriver, you need to have one of the supported languages installed on your computer. In this post, we will be focusing specifically on Python.

On Windows

First, you will have to install Python on your computer. Head over to the official Python download page and grab the latest version for Windows.

Download: Python for Windows

Then, install Selenium WebDriver using Pip, the official Python package manager. Type in the following command to install Selenium:

If the above command throws an error, you can execute the pip command using the -m flag. The -m flag stands for module name and allows you to pass a module at the time of invoking Python.

On Linux

Installing Python on Linux is easy. All you need to do is download the official Python package using the default package manager of your distribution.

On Debian,

On Arch,

With Fedora,

On CentOS,

Now, to install Selenium WebDriver, open your terminal and enter:

or

On macOS

To install Python on your Mac, download the latest binary package from the official Python download page.

Download: Python for Mac

After installing Python, launch the terminal and type:

Alternatively, you can launch pip using the -m flag while invoking Python:

How to Setup Selenium WebDriver With Python

In order to use Selenium WebDriver for web automation, you will have to download a driver that integrates with the browser of your choice. This driver will allow Selenium to control the browser and automate the commands that you write in your scripts.

Selenium currently supports Google Chrome, Firefox, Microsoft Edge, and Safari. The official webdriver for Chrome is the ChromeDriver, whereas Geckodriver is the official webdriver for Firefox.

Note that you will have to add the webdriver to your system’s PATH variables in order to use Selenium.

On Windows

To add the webdriver to PATH variables in Windows:

Download the webdriver of your choice from the aforementioned link Extract the downloaded ZIP file and copy the webdrivername file to a specific location on your local storage Now, copy the path of the executable file Open This PC and right-click on the empty area, selecting Properties from the list of options Click on the Change Settings option. Switch to the Advanced tab and click Environment variables Under System Variables, scroll down until you find an entry titled Path Highlight that entry and click on Edit Click on the New button and type in the path of the webdriver in the respective field Click on OK to save the settings

To check if the driver is installed properly, launch a new Command Prompt window and enter the name of the webdriver. For example, if you are using ChromeDriver, type in chromedriver and press Enter.

If the driver is not installed properly, an error will occur.

Configure the Webdriver PATH Variable on Linux

To add the webdriver to PATH variables on Linux:

Download the webdriver for Linux using the link mentioned above Extract the downloaded ZIP file and copy the webdrivername file to a specific location on your system storage Now, copy the path of the executable file Launch the terminal by pressing Ctrl + Alt + T Edit the user profile file—while you can open the file with any Linux text editor of your choice, in this case, we will be using Nano sudo nano /home/username/. profile Append the following line to the end of the file export PATH=$PATH:/pathtodriver/webdriver Save the file

On macOS

Setting up the webdriver on a macOS device is easy. To do this:

Download the webdriver for Linux using the links mentioned above Extract the downloaded ZIP file and copy the webdrivername file to a specific location on your system storage Now, copy the path of the executable file Open up the terminal Edit the paths file on your system by entering the command given below sudo nano /etc/paths Enter your system password for verification Paste the path of the webdriver at the end of the file Save the file and quit

You can check if the webdriver is installed properly by typing the name of the webdriver in the terminal.

Automating a Browser With Selenium WebDriver

With the power of Selenium, browser automation has never been easier. You can automate some basic repetitive tasks yourself by simply writing a piece of code. Cybersecurity analysts can benefit as well by automating web penetration testing using Selenium.

Although Selenium is the first choice of many developers who frequently test web applications, there are some other testing frameworks as well that are worth a try.