+91 9790664230
kumar.arun211@gmail.com

Python Selenium WebDriver environment setup

Blog to learn python selenium from java selenium

Python Selenium WebDriver environment setup

In this post, we will mainly discuss Python Selenium WebDriver setup required to start writing python selenium scripts.

Selenium WebDriver is one of the most popular test automation tool for Web UI Automation. This Web UI Automation includes automatic execution of the actions performed in a web browser window like navigating to a website, clicking on links and buttons, filling forms with text boxes, check boxes, radio buttons and drop downs, navigating through web pages, handling pop-ups and so on. Selenium WebDriver can interact with all types of Web browsers available like Firefox, Internet Explorer, Safari, and Chrome, etc using respective browsers native driver.

Selenium is an open source library and is available in different programming languages to perform the Web UI Automation testing. Python is one of the selenium supported language.

Selenium WebDriver library for Python enables us to utilize all the features available with Selenium WebDriver to perform automated testing (local, remote and distributed testing) of browser based applications.

Python Selenium WebDriver library is compatible with all Python versions from Python2.6 to latest versions. Below are the 4 steps that needs to be followed to setup environment for Python Selenium WebDriver.

  1. Install Python
  2. Install Selenium WebDriver Package for Python
  3. Select and setup Python Editor
  4. Download Browser drivers

Install Python:

Python is by default installed on Linux distributions, MAC OS X, and Unix machines. However it needs to be installed separately on Windows machines.

Python installers for different supported operating systems are available here.

Python installer also installs <pip> tool which is Python’s package manager. It facilitates the installation of other required packages like Selenium Webdriver.

Install Selenium WebDriver Package for Python:

There are two different ways to set up Selenium Webdriver with Python.

First method, use <pip> installer tool to install python.

pip install selenium

This approach is preferred among all the methods available for installing Selenium with Python. The above commands will set up the Selenium WebDriver library on the system with all modules and classes required to create automated test scripts using Python.

The <pip> tool will automatically download the latest version of the Selenium package and install it on your machine. To download specific versions of selenium version, use below command.

pip install selenium==3.11.0

There is an optional -U flag; Passing this flag will upgrade the existing version of the installed package to the latest version.

pip install -U selenium

Second method is to manually download source code and run setup python script available inside source code folder.

You can download latest release from this link.

OR

You can see all available Selenium WebDriver versions here.

Download the zip file, extract the source, go into the folder and run below command.

python setup.py install

Select and setup Python Editor:

After Python and Selenium WebDriver set up, next important step is to either pick an editor or an IDE (Integrated Development Environment) for writing the test scripts. A good editor or an IDE makes coding simple and helps to code faster with its in-built features.

What do we expect from an IDE?

1. GUI based code editor with Code Completion feature
2. Syntax highlighting feature
3. Code explorer for functions and classes
4. Refactoring
4. Option for managing project structure
5. Debugging tools
6. Unit testing support

Text editors like Vim, Notepad or Subulime Text can be used to write the Python test scripts. But IDEs are more convenient to work on large projects.

Some of the popular Python IDEs for development:

1. PyCharm
2. PyDev
3. Visual Studio
4. Spyder

There are many more IDEs available; Download the one which is best suited for you.

Download Browser drivers:

From SeleniumHQ website

The biggest change in Selenium recently has been the inclusion of the WebDriver API. Driving a browser natively as a user would either locally or on a remote machine using the Selenium Server it marks a leap forward in terms of browser automation.

Selenium WebDriver fits in the same role as RC did, and has incorporated the original 1.x bindings. It refers to both the language bindings and the implementations of the individual browser controlling code. This is commonly referred to as just “WebDriver” or sometimes as Selenium 2.

Selenium 1.0 + WebDriver = Selenium 2.0

  • WebDriver is designed in a simpler and more concise programming interface along with addressing some limitations in the Selenium-RC API.
  • WebDriver is a compact Object Oriented API when compared to Selenium1.0
  • It drives the browser much more effectively and overcomes the limitations of Selenium 1.x which affected our functional test coverage, like the file upload or download, pop-ups and dialog barrier
  • WebDriver overcomes the limitation of Selenium RC’s Single Host origin policy.

You can download webdriver executable from respective browser driver repositories. For more information about download locations, please read our article.

Let us know your comments in comment box. Happy reading.

 

Leave a Reply

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

© 2018 Copyrights. All Rights Reserved. Arunkumar Velusamy