Table of Contents
In this article, we will see how to install selenium webdriver in python3 using easy steps. Webdriver is an API and protocol that act as an interface for controlling the behavior of web browsers. Each browser is backed by a specific WebDriver implementation, called a driver. The driver is the component responsible for delegating down to the browser, and handles communication to and from Selenium and the browser. Selenium WebDriver refers to both the language bindings and the implementations of the individual browser controlling code. This is commonly referred to as just WebDriver. More on official website.
Important Features
- WebDriver is designed as a simple and more concise programming interface.
- WebDriver is a compact object-oriented API.
- It drives the browser effectively.
How to Install Selenium WebDriver in Python 3 [Easy Steps]
Also Read: How to Plot Multiple Graphs in Python Using Matplotlib
Step 1: Prerequisites
a) You should have a running Windows
or Linux
System.
b) You should have an active Internet Connection.
c) You should have access to install a package in your System.
Step 2: Install Python 3
If you don't have python3 already installed in your System then you can install it on a Ubuntu/Debian based system using sudo apt install python3
command as shown below. If you are using RHEL/CentOS based systems then you can either use sudo yum install python3
or sudo dnf install python3
command. If you are using Windows based systems, then go to official website and download and install the latest software from there. In our case, since python3 is already installed so it won't do anything as you can see below.
cyberithub@ubuntu:~$ sudo apt install python3
Reading package lists... Done
Building dependency tree
Reading state information... Done
python3 is already the newest version (3.8.2-0ubuntu2).
The following packages were automatically installed and are no longer required:
libjs-jquery-ui pypy-lib python-matplotlib-data python3-cycler python3-kiwisolver
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Step 3: Install pip3
Since selenium webdriver will be installed through pip3 utility so it's important to install this utility first using sudo apt install python3-pip
command as shown below. If it is already installed and available, then you can directly go ahead and install selenium webdriver using next step.
cyberithub@ubuntu:~$ sudo apt install python3-pip Reading package lists... Done Building dependency tree Reading state information... Done The following packages were automatically installed and are no longer required: libjs-jquery-ui pypy-lib python-matplotlib-data python3-cycler python3-kiwisolver Use 'sudo apt autoremove' to remove them. The following NEW packages will be installed: python3-pip 0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded. Need to get 231 kB of archives. After this operation, 1,050 kB of additional disk space will be used. Get:1 http://in.archive.ubuntu.com/ubuntu focal-updates/universe amd64 python3-pip all 20.0.2-5ubuntu1.6 [231 kB] Fetched 231 kB in 11s (21.6 kB/s) Selecting previously unselected package python3-pip. (Reading database ... 258471 files and directories currently installed.) Preparing to unpack .../python3-pip_20.0.2-5ubuntu1.6_all.deb ... Unpacking python3-pip (20.0.2-5ubuntu1.6) ... Setting up python3-pip (20.0.2-5ubuntu1.6) ... Processing triggers for man-db (2.9.1-1) ...
Step 4: Install Selenium Library
You can now use pip3 python package to install selenium webdriver by using sudo pip3 install selenium
command as shown below.
cyberithub@ubuntu:~$ sudo pip3 install selenium
Collecting selenium
Downloading selenium-4.5.0-py3-none-any.whl (995 kB)
|████████████████████████████████| 995 kB 3.1 MB/s
Collecting urllib3[socks]~=1.26
Downloading urllib3-1.26.12-py2.py3-none-any.whl (140 kB)
|████████████████████████████████| 140 kB 11.6 MB/s
Collecting trio-websocket~=0.9
Downloading trio_websocket-0.9.2-py3-none-any.whl (16 kB)
Collecting trio~=0.17
Downloading trio-0.22.0-py3-none-any.whl (384 kB)
|████████████████████████████████| 384 kB 3.1 MB/s
Collecting certifi>=2021.10.8
Downloading certifi-2022.9.24-py3-none-any.whl (161 kB)
|████████████████████████████████| 161 kB 3.2 MB/s
Collecting PySocks!=1.5.7,<2.0,>=1.5.6; extra == "socks"
Downloading PySocks-1.7.1-py3-none-any.whl (16 kB)
Collecting async-generator>=1.10
Downloading async_generator-1.10-py3-none-any.whl (18 kB)
Collecting wsproto>=0.14
Downloading wsproto-1.2.0-py3-none-any.whl (24 kB)
Requirement already satisfied: attrs>=19.2.0 in /usr/lib/python3/dist-packages (from trio~=0.17->selenium) (19.3.0)
Collecting outcome
..........................................................
Step 5: Install Chrome WebDriver
Depending on the browser, you can choose to install Webdriver. In our case, we are installing webdriver for Google Chrome
browser by using sudo apt install chromium-chromedriver
command as shown below.
cyberithub@ubuntu:~$ sudo apt install chromium-chromedriver [sudo] password for cyberithub: Reading package lists... Done Building dependency tree Reading state information... Done The following packages were automatically installed and are no longer required: libjs-jquery-ui pypy-lib python-matplotlib-data python3-cycler python3-kiwisolver Use 'sudo apt autoremove' to remove them. The following additional packages will be installed: chromium-browser The following NEW packages will be installed: chromium-browser chromium-chromedriver 0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded. Need to get 50.8 kB of archives. After this operation, 242 kB of additional disk space will be used. Do you want to continue? [Y/n] Y ....................................................
Step 6: Test Chrome WebDriver
Once the webdriver is installed successfully, you can test it by using chromedriver
command as shown below.
cyberithub@ubuntu:~$ chromedriver Starting ChromeDriver 105.0.5195.125 (1e8949033cc650c8496b3b0af7cd54372f7ff62b-refs/branch-heads/5195@{#1107}) on port 9515 Only local connections are allowed. Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe. ChromeDriver was started successfully.
Step 7: Upgrade Selenium
If you already have selenium installed, then to upgrade it to the latest version by using sudo pip3 install -U selenium
command as shown below.
cyberithub@ubuntu:~$ sudo pip3 install -U selenium
[sudo] password for cyberithub:
Requirement already up-to-date: selenium in /usr/local/lib/python3.8/dist-packages (4.5.0)
Requirement already satisfied, skipping upgrade: urllib3[socks]~=1.26 in /usr/local/lib/python3.8/dist-packages (from selenium) (1.26.12)
Requirement already satisfied, skipping upgrade: trio~=0.17 in /usr/local/lib/python3.8/dist-packages (from selenium) (0.22.0)
Requirement already satisfied, skipping upgrade: trio-websocket~=0.9 in /usr/local/lib/python3.8/dist-packages (from selenium) (0.9.2)
Requirement already satisfied, skipping upgrade: certifi>=2021.10.8 in /usr/local/lib/python3.8/dist-packages (from selenium) (2022.9.24)
Requirement already satisfied, skipping upgrade: PySocks!=1.5.7,<2.0,>=1.5.6; extra == "socks" in /usr/local/lib/python3.8/dist-packages (from urllib3[socks]~=1.26->selenium) (1.7.1)
Requirement already satisfied, skipping upgrade: sniffio in /usr/local/lib/python3.8/dist-packages (from trio~=0.17->selenium) (1.3.0)
Requirement already satisfied, skipping upgrade: sortedcontainers in /usr/local/lib/python3.8/dist-packages (from trio~=0.17->selenium) (2.4.0)
Requirement already satisfied, skipping upgrade: attrs>=19.2.0 in /usr/lib/python3/dist-packages (from trio~=0.17->selenium) (19.3.0)
Requirement already satisfied, skipping upgrade: outcome in /usr/local/lib/python3.8/dist-packages (from trio~=0.17->selenium) (1.2.0)
Requirement already satisfied, skipping upgrade: async-generator>=1.9 in /usr/local/lib/python3.8/dist-packages (from trio~=0.17->selenium) (1.10)
Requirement already satisfied, skipping upgrade: idna in /usr/lib/python3/dist-packages (from trio~=0.17->selenium) (2.8)
Requirement already satisfied, skipping upgrade: exceptiongroup>=1.0.0rc9; python_version < "3.11" in /usr/local/lib/python3.8/dist-packages (from trio~=0.17->selenium) (1.0.0rc9)
Requirement already satisfied, skipping upgrade: wsproto>=0.14 in /usr/local/lib/python3.8/dist-packages (from trio-websocket~=0.9->selenium) (1.2.0)
Requirement already satisfied, skipping upgrade: h11<1,>=0.9.0 in /usr/local/lib/python3.8/dist-packages (from wsproto>=0.14->trio-websocket~=0.9->selenium) (0.14.0)
Step 8: Uninstall Selenium
Once you are done with selenium, you can choose to uninstall it from your System by using sudo pip3 uninstall selenium
command as shown below.
cyberithub@ubuntu:~$ sudo pip3 uninstall selenium Found existing installation: selenium 4.5.0 Uninstalling selenium-4.5.0: Would remove: /usr/local/lib/python3.8/dist-packages/selenium-4.5.0.dist-info/* /usr/local/lib/python3.8/dist-packages/selenium/* Proceed (y/n)? y Successfully uninstalled selenium-4.5.0