Looking For Anything Specific?

How to Install Selenium WebDriver on Any Computer With Python

Automation has become an integrated part of the software development industry. Many frameworks have been developed that allow users to enhance their workflow by automating repetitive tasks with a few lines of code.

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:

  1. Selenium IDE (Integrated Development Environment)
  2. Selenium Remote Control
  3. Selenium WebDriver
  4. 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:

pip 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.

python -m pip install selenium

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,

sudo apt-get install python

On Arch,

sudo pacman -S python

With Fedora,

sudo dnf install python

On CentOS,

sudo yum install python

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

pip install selenium

or

python -m pip install selenium

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:

pip install selenium

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

python -m pip install selenium

Related: The Best Automation Tools to Let Freelancers Reclaim Their Time

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.

Driver Name Supported Browser Download
ChromeDriver Google Chrome Download
GeckoDriver Firefox Download
WebDriver Microsoft Edge Download
WebDriver Apple Safari Download

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:

  1. Download the webdriver of your choice from the aforementioned link
  2. Extract the downloaded ZIP file and copy the webdrivername file to a specific location on your local storage
  3. Now, copy the path of the executable file
  4. Open This PC and right-click on the empty area, selecting Properties from the list of options
    my computer properties
  5. Click on the Change Settings option.
    change windows settings
  6. Switch to the Advanced tab and click Environment variables
    environment variables settings
  7. Under System Variables, scroll down until you find an entry titled Path
  8. Highlight that entry and click on Edit
    edit the path variable
  9. Click on the New button and type in the path of the webdriver in the respective field
    add new path variable
  10. 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.

'chromedriver' is not recognized as an internal or external command,
operable program or batch file.

Configure the Webdriver PATH Variable on Linux

To add the webdriver to PATH variables on Linux:

  1. Download the webdriver for Linux using the link mentioned above
  2. Extract the downloaded ZIP file and copy the webdrivername file to a specific location on your system storage
  3. Now, copy the path of the executable file
  4. Launch the terminal by pressing Ctrl + Alt + T
  5. 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
  6. Append the following line to the end of the file
    export PATH=$PATH:/pathtodriver/webdriver
  7. Save the file

On macOS

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

  1. Download the webdriver for Linux using the links mentioned above
  2. Extract the downloaded ZIP file and copy the webdrivername file to a specific location on your system storage
  3. Now, copy the path of the executable file
  4. Open up the terminal
  5. Edit the paths file on your system by entering the command given below
    sudo nano /etc/paths
  6. Enter your system password for verification
  7. Paste the path of the webdriver at the end of the file
  8. 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.


Post a Comment

0 Comments