How to Install and setup Selenium with chrome on Linux (Debian)

Using Selenium, you can run predefined code to navigate multiple pages, closing tickets, notating projects, or adding tasks.

In this guide will see how to install and set up selenium with chrome on linux and Other Debian-based systems.

Basic Requirements

We will use a python program to automate. Before this, make sure that you have installed the following Package.

Python3 installed on your Ubuntu/Debian rig.
PIP3 installed on your Ubuntu/Debian rig.
Google chrome installed on your Ubuntu/Debian system.

Now we will start the installation process.

Step 1: Create Python3 Virtual Environment

First of all we install virtualenv using pip3 command type the following command in terminal.
$ sudo pip3 install virtualenv

It’s OK to use sudo for this initial command even though your debian distribution may warn against it… notice from here forward we drop off the sudo.

A benefit of installing virtualenv will create isolated python3 environment, which will ensure that you don’t wreck your old programs.

Modules you import for this project will save in the current project directory, not globally.

After virtualenv download you need to create project directory at any location. To create directory use

$ mkdir -p selenium_chrome/drivers

cd to created folder directory selenium_chrome using change directory command.

$ cd selenium_chrome

Now we will setup or create Python Virtual environment in the current project directory using the below command:

Command Syntax

$ virtualenv .virtualenvirnomentname

In mycase (for demo purposes)

$ virtualenv .dem_environment

Create Virtual Environment

After completing above step now we want to activate the Python virtual environment to activate pass command:

Command Syntax

$ source .virtualenvironmentname/bin/activate

In mycase

$ source .dem_environment/bin/activate

Step 2: How to Install Selenium Python Library

It is pretty simple to install selenium on Python Because selenium is available on the Python PyPI repository So, you need to leverage the pip command:

$ pip3 install selenium

The important thing is getting a non-global instance going because selenium and python are changing all the time and dependency hell happens occasionally breaking installation as one piece is upgraded and not the other. Once you get a working instance going you can keep that instance chugging away as your global installation can update/upgrade with the system.

Selenium is installed successfully, and Now we will install Chrome driver.

Step 3: Installing the Chrome Driver

A single pip3 command will make short work of installing your Chrome driver.

pip3 install webdriver-manage

Paste the following code into a script:

import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
chromeOptions = Options()
chromeOptions.headless = True
browser = webdriver.Chrome(executable_path=”./drivers/chromedriver”, options=ch>
browser.get(“https://www.glencoulson.com”)
print(“Title: %s” % browser.title)
browser.quit()

One comment

Leave a Reply

Your email address will not be published. Required fields are marked *