How to Install and Setup Selenium With Python and Ubuntu

How to Install and Setup Selenium With Python and Ubuntu

Published at - Dec 20, 2021

Good day, Developers! I’ll talk about Selenium and how to install Selenium on your Ubuntu operating system. I’ll try to address some fundamental questions about Python and Selenium automation with Ubuntu as the operating system. Let’s get this party started right now.

The best course to learn Selenium

What is Selenium?

Selenium is an open-source umbrella project for web browser automation, it provides tools and libraries for automation and web scrapping. It is broadly used for automation testing web applications. Selenium is used for the following operations:

  1. Cross-browser automation testing
  2. Web scrapping
  3. Web automation

Selenium is available in many languages such as JavaScript (Node. js), Python, Ruby, Java, Kotlin, and C#. I am going to use it with the Python programming language. To get started with it we need to install Python in our Ubuntu system.

Install Python and Pip in Ubuntu

Python official website

Although Ubuntu comes with pre-installed the latest version of Python. you can check by running python3 -vfrom your terminal and it will be returned the installed version of Python. If it is not installed You have to follow the below steps.

To install Python 3.8 in our Ubuntu system we have run the following commands from the terminal. To open the terminal press ctrl+alt+t keys and type the following one by one:

sudo apt-get update
sudo apt -y upgrade
python3 -V

If you get Python 3.*.* on your terminal, that means the Python is already installed and you need not perform any additional steps. If it is not fo you have to perform the following actions:

sudo apt-get install python3.8 -y

This will install Python 3.8 in Ubuntu you can check and verify by running python3 -v the command. Now its time to install PIP (Python package manager)

sudo apt-get install python3-pip -y

Install Selenium package

To install the Selenium Python package we have to run the following command from the terminal:

pip3 install selenium

To learn more about the Selenium package for Python click here.

Download Chrome driver

Now you have to download the chrome driver as per your chrome browser installed in our system. To see your chrome version click on 3 dots from the top right corner > Help > About Google Chrome or just click here.

Once you have your Chrome browser now you can navigate this website and download your driver.


Python Script

This is the final step in which we will finally run automation and perform some actions. You can learn in more detail from here.

import time
from selenium import webdriver
driver = webdriver.Chrome('/usr/local/bin/chromedriver')  # Optional argument, if not specified will search path.
time.sleep(5) # Let the user actually see something!
search_box = driver.find_element_by_name('q')
search_box.send_keys('ChromeDriver') # typing in serach box
search_box.submit() # serach query
time.sleep(5) # Let the user actually see something!
driver.quit() # quit and close

Code sample available here

Working Demo 👇

Screen recording

Final words

We have learned some basics about getting started with Selenium with Python on the Ubuntu operating system. I hope this will help to get started with Selenium.

Note: Many websites do not allow automation, as we all know, and I am not advocating for it. This article was prepared only for the sake of education.

I hope you enjoyed reading this lesson; you can follow me to read more tutorials from me in the future. Thank you for your time.

By evolving a Medium partner, you can support me and your other favored writers. Gratitude! 👇

Join Medium with my referral link - Harendra Verma

Discover more additional about Selenium

More content at Sign up for our free weekly newsletter here.

How to Install and Setup Selenium With Python and Ubuntu was originally published in Python in Plain English on Medium, where people are continuing the conversation by highlighting and responding to this story.

Follow Us

Follow us on facebook Click Here

Facebook QR
Scan from mobile
Join our telegram channel Click Here
Telegram QR
Scan from mobile