How to install Selenium on Linux and automate your web tests

How to  install Selenium on Linux and automate your web tests

Selenium is a web testing toolkit that allows you to test a web application in any browser of your choice. It does this with the help of a software called WebDriver which allows you to emulate a web browser and test your web application in it.

In this post I am going to show you how to test a simple CRUD application, by automating link clicking and form filling.

Software versions
Selenium (2.44.0)
Python 3.4.2
Linux kernel 3.13.0-37-generic and Mint 17.1 for Desktop.

Installing Selenium on Linux
To install the Selenium Bindings for Python on Linux use pip.

[leo@selenium-on-linux]$ virtualenv -p /usr/bin/python3 venv-3.4
[leo@selenium-on-linux]$ source venv-3.4/bin/activate
[leo@selenium-on-linux]$ pip3 install selenium

The webdriver for Firefox is installed along with Selenium but if you want to test your applications on chrome then you need to download the chrome driver and ensure chrome is installed on your Linux distro.

Getting started with the code.
The first thing you need to do is create an instance of the webdriver.

from selenium import webdriver


Next you need to specify the url of the web application you need to test. I will be using a custom CMS application which is used to create, read, update and delete posts for this demonstration. Below is the screenshot of the app.

Install Selenium on Linux

assert "Post Page Title" in driver.title

The above code will fetch the web page and check if the web page has been successfully fetched by matching the content in the page title.

Now let’s test the “Create”, i.e add a post.

  link=driver.find_element_by_link_text("Add new")
  assert "Save" in driver.page_source

In the code above I use “find_element_by_link_text()” to perform actions on the anchor HTML element which contains the text “Add new”. You can get elements with their ID or name or even by class name. You can click on elements with the “click()” method.

On clicking the “Add new” link you get the page to create a post.

Install Selenium on Linux

Here we need to fill in the title, body, category, select whether the post will be published and then click on the “Save” button to add the post.

So let’s fill in the form with some text

#Add posts
        title.send_keys("Your Title text here")

        content.send_keys("Your Body text here")

        category.send_keys("Your category text here")

Below is the html of the form elements.

As I mention earlier you can fetch an element by it’s name with “find_element_by_name(“element name”)”. You can then perform an action on it like fill it with text using “send_keys()”.

For the “select” element we will need to import the “Select” class.

from import Select

 select = Select(driver.find_element_by_name('published'))
 published=select.select_by_value("Your option value")

Now we need to click on Save, however the “Save” button does not have a name attribute hence we need to use the class name.

 assert "Add was successful" in driver.page_source

Similarly the code for update is

 #Edit Posts
        assert "Save" in driver.page_source

        title.send_keys("Selenium web test edit")
        content.send_keys("Selenium web test edit")
        category.send_keys("Selenium web test edit")

        select = Select(driver.find_element_by_name('published'))

        assert "Update was successful" in driver.page_source

And the code for delete is

 #Delete Posts
 assert "Post was deleted successfully" in driver.page_source

The complete source code is available at

I have also written a scaffolding app which will automatically creates tests for your modules along with the CRUD modules, you can download it from and read about it at Building database driven apps in Python with Flask

You can view the code in action in the video below.

Comments and feedback is welcome.

Ref (

Follow me

Leo G

Is a Linux Hobbyist and Enthusiast. He Strongly believes in OpenSource Software and would like you to view and download his software at
Follow me

  • Pingback: How to install Selenium on Linux and automate y...()

  • Pingback: How to install Selenium on Linux and test your web applications | Linux Press()

  • Pingback: How to install Selenium on Linux and test your web applications | Zbyněk Svoboda()

  • Pingback: Links 15/3/2015: Linux Lite 2.4, OpenELEC 5.0.6 | Techrights()

  • jwebuser

    Great, thank you for this post!

    • Leo G

      You welcome

  • White Ninja

    Good article with step by step explanation. I am web scraper ( here is my website to look at : ) and using selenium for my web scraping work since last 6 years.

  • ScraperHunk

    Selenium is handy when a particular website is protected by anti web scraping technology. Here is my website to look at :

  • Silambu Mani

    Exception in thread “main” java.lang.UnsupportedClassVersionError: org/openqa/selenium/WebDriver : Unsupported major.minor version 52.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(
    at Method)
    at java.lang.ClassLoader.loadClass(
    at sun.misc.Launcher$AppClassLoader.loadClass(
    at java.lang.ClassLoader.loadClass(
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(
    at java.lang.Class.getMethod0(
    at java.lang.Class.getMethod(
    at sun.launcher.LauncherHelper.getMainMethod(
    at sun.launcher.LauncherHelper.checkAndLoadMain(

    hai i am running webdriver code eclipse in linux 14.04 LTS showing the error like console how to clear the error..