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.
- Install Python
- Install Selenium WebDriver Package for Python
- Select and setup Python Editor
- Download Browser drivers
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:
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.
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?
- GUI based code editor with Code Completion feature
- Syntax highlighting feature
- Code explorer for functions and classes
- Option for managing project structure
- Debugging tools
- 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:
3. Visual Studio
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
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 below. Happy reading.