Using Selenium with Python in Eclipse

Arun
20 min read
Featured Image

What is Python?

Python is an interpreted, object-oriented, high-level programming language with dynamic semantics. Python's simple, easy to learn syntax emphasizes readability and therefore reduces the cost of program maintenance.

Python language is supported by Selenium and can be utilized for testing of web applications.
Some of the advantages of Python are:

  • Open-source and community supported
  • Third-party modules can be integrated
  • Large set of libraries available to use
  • Ease of learning with simple tutorials
  • Support available in sites like stack overflow etc..

What is Eclipse?

Eclipse is an integrated development environment (IDE) and famous for Java IDE, but can be used for C/C++ IDE and PHP IDE also. The language support and other features can be added to the default packages using the Eclipse Marketplace.

Step.1 Install Python support in Eclipse

  1. Update Java to the latest version. Install Python 2.7 or 3.x version.
  2. Update the Eclipse IDE to the latest version. Use Eclipse Help Menu >> Check for Updates and Install the updates. Or goto http://www.eclipse.org/downloads/eclipse-packages/ and download and install the latest version.
  3. Select the Eclipse Help Menu >> Eclipse Marketplace
  4. Type "PyDev" in the Search field and press "Install" button in the PyDev solution
  5. In the "Confirm Selected Features" window press "Confirm" button
  6. In the "Review Licenses" window select "I accept.." option and press "Finish" button
  7. When the installation is complete, restart Eclipse to make the changes take effect.

Step.2 Set the Python Preferences in Eclipse

  1. Open Eclipse window menu >> Preferences option
  2. Select "PyDev" option and Expand "Interpreters" and Select "Python Interpreter" and Select "New" button
  3. Using the "Browse" button browse to the Python executable python.exe eg: C:/Python27/python.exe
  4. Select "OK" in the folder selection window, with all the folder selections selected.
  5. Select "Apply" and then "OK" in the "Preferences" window to apply the changes.
  6. Allow the eclipse to access network if windows firewall blocks the access

Step.3 Check the Python installation in Eclipse

  1. Right-click in Package manager and select New >> Other option Eclipse Package manager
  2. Expand "PyDev" in the wizard window and select "PyDev Project" Eclipse PyDev Project
  3. Enter project name and press "Finish" option Eclipse PyDev Project name
  4. Select "Yes" option in the Open Associated Perspective? dialog
  5. Right-click in the created project and add "PyDev Package" Eclipse PyDev Package
  6. Enter the name and click "Finish" button Eclipse PyDev Module
  7. Right-click in the created package and add "PyDev Module" Eclipse PyDev Module
  8. Enter the name and click "Finish" button Eclipse PyDev Module name
  9. Keep the template click "OK" button Eclipse Python template
  10. Enter the Python code and right-click and select "Python Run" Eclipse Python Hello World

Step.4 Install Selenium WebDriver Language Bindings for Python

  1. Goto http://www.seleniumhq.org/download/ and select download in Python section Selenium WebDriver Language Bindings
  2. Download the source code in the page eg: selenium-3.9.0.tar.gz Selenium WebDriver source code
  3. Extract the files in to a folder and open command window in the folder
  4. Close the Eclipse if open
  5. Type command:- C:/Python27/python.exe setup.py install Selenium WebDriver Python install
  6. When Install is Finished, start Eclipse
  7. When Eclipse detects selenium is installed, "PYTHONPATH changes detected" window is displayed.
  8. Keep the default selections and click "Apply selected changes" button
  9. Now write selenium codes in Python and right-click and select "Python Run" Eclipse Python Getting Started
  10. The example is explained here http://selenium-python.readthedocs.io/getting-started.html#example-explained