The following Selenium with Python tutorial will cover all the fundamentals in order to create a proper test automation project.

Python is an object oriented programming language, it runs on Linux, Windows and Mac which turns it into cross platform. In addition, Python is a scripting language. Hence, both compilation and linkage are not required.Python was built with an emphasis on readability and simplicity, it is perfectly scalable and in terms of performance, Python can grant high performance.

The popularity of Python derives from its shallow learning curve, its readability and the enormous supply of libraries. Among others things, Python can handle compressed documents, mathematical functions, regular expressions, data communications, graphic interfaces, working with OS services and more.

*Interestingly enough, Python isn’t named after a snake after all. But rather, a comic British line up!

Without a doubt, Selenium project couldn’t overlook this language when deciding to support different programming languages for Selenium WebDriver. Notwithstanding, it’s not popular as JavaScript or Java under Selenium’s domain, however it’s well known among test automation and API developers.

In this post we’ll discuss test automation using Selenium with Python. The article will consist of 2 parts:

Part 1 (Current): Setting up the development environment

Downloading and installing Python’s environment Getting to know Python’s Interactive Shell IDE selection and installation

Part 2: Selenium examples (actions and test cases)

An automatic action in Selenium and Python An automation test in Selenium and Python

1. Downloading and installing Python’s environment

In order to download Python, enter Python’s official website: https://www.python.org/downloads and download the relevant version. I used 7.2 (It’s a msi document).

The next step is to define the Environment Variables in the OS for this language: right-click>My Computer>System Properties>Advanced System Settings and then choose the Environment Variables.

Under System variables, we’ll open a parameter named ‘Path’ by clicking on ‘Edit’ and insert 2 new paths: C:\Python27\Scripts and C:\Python27\Lib\site-packages (Remember to separate both values by ‘ ; ‘).

Continuing on with 4 clicks on ‘OK’ to reach the main page.

For the sake of making sure the installation and configuration turned out successful, open the Command line and type: ‘python’, the message below will appear:

2. Getting to know Python’s Interactive Shell

To get to know Python better, first open CMD and type ‘python’ or open the Interactive Shell of Python explicitly (choosing- ‘Python Command Line’).

From here on, we are ready to start writing in Python. First function we can start checking is a mathematical function:

We will print the ‘Hello word’ for the screen:

We’ll work with variables:

And use loops- a program that retrieves the values of Fibonacci’s series:

3. IDE selection and installation

Similar to other languages, Python owns an honorable variety of work environments: some commercial and the remain are open source environments. A few well known environments are: PyCharm by JetBrains, an open source project by NetBeans, the priced addon for Eclipse- LiClipse and the free addon to Eclipse- PyDev.

In this post I’ll demonstrate the work with PyDev for Eclipse IDE which is popular among a substantial number of Java test automation developers. If you have the Aptana plug-in installed, it’s certainly suitable here as well.

Now, all we’ve left with is configuring the Interpreter of Python in Eclipse: Windows> Preferences, PyDev> Interpreters> navigate to Python Interpreter:

After clicking on ‘New’, a window will open to configure its path in the location where Python is installed:

Next, click ‘OK’ and the following will appear:

Once again click ‘OK’, to navigate you to the following:

Click again on ‘OK’ and wait until the installation process is finished:

Stay tuned for the next part of Selenium with Python tutorial, where we’ll open a Python project in Eclipse, install Selenium and begin writing tests in PyDev environment.

Reference