Install Python

We have to install python in our operating system to use selenium python bindings for our project.

1. Navigate to https://www.python.org/downloads/

2. Download the latest version of the Python or a stable release, for this tutorial we will be using python 3 (version above 3 are considered as 3 in general terms)
download-python-selenium

3. Install the python installer (I am on the Windows 10 operating system), and select add the path
python-installer-selenium

4. After installing, open the command prompt, and type python, you should get version and >>> python editor. If you get them, then your python installation is successful.

cmd-to-check-python-installtion



Open Webpage in selenium python

Install Selenium python bindings

  1. We should have python installed in your system before you try to install selenium
  2. You can install selenium just by typing the following command on cmd (not on python editor) : pip install -U selenium
    pip-install-selenium
  3. Now open the python editor just simply entering word python on the command prompt.
  4. The below command will not throw an exception if your selenium is installed successfully
    from selenium import webdriver​
Only in case if you are not able to install the selenium using the pip command then only try the below steps otherwise ignore the below steps.
Install selenium Manually:
  1. Sometimes pip command fails to install selenium either due to proxy issues or due to system configuration issues, in that we have to use the below steps to install selenium.
  2. Navigate to https://pypi.python.org/pypi/selenium
  3. Click on the download button
    selenium-pi-python
  4. Download the applicable format based on your operating system, below image shows for windows operating system.
    selenium-tar-python
  5. Extract the downloaded zipped file to your local system, and the content should look like below.
  6. Open command prompt/terminal and navigate to that the unzipped folder.
  7. Enter the following command to install selenium:
    python setup.py install or python install setup.py​

  8. Now open python editor just simply entering word python on the command prompt.
  9. The following command will not throw an exception if your selenium is installed successfully
    from selenium import webdriver.​

CSS Selector in Selenium Python

Install pyDev with eclipse

We cannot code all the things in the python editor, because as the code block increases it becomes difficult to continue with coding. To edit the python code quickly, we have to use an IDE for development. In this tutorial, I will be using Eclipse with PyDev.

PyDev is a kind of plugin for the eclipse to support the Python programming.

1. After installing Eclipse, Goto Help >Eclipse marketplace
market-place-selenium-python

2. Now search for "pyDev" and install the software
pydev-selenium-python

3. Accept the License and Restart the eclipse.
4. We have to open PyDev perspective to edit python code, Window > Perspective > Open Perspective > Other, and choose PyDev
open-perspective-python-selenium
pydev-perspective-python-selenium

5. Create first Project, File > New > PyDev Project
pydev-first-project-selenium

6. For the first time, we have to set the interpreter, click to configure the interpreter.
configure-interpreter-python-selenium

7. Click on the Auto-config option, and then finish the creating project wizard.
pydev-package-python-selenium

8. Right-click on the python project and Create a new Pydev Module, and select blank
pydev-package-python-selenium


9. Enter the following command in the coding area and Click the run button in Eclipse.

from selenium import webdriver


10. You can choose how you want to run either Just python program or as UnitTest Program
python-run-test-first-selenium

Python Selenium find the element

Console on PyDev

Unlike other programming languages, Python provides a live editor, which is you can control the browser entering command by command.

I am not talking about debugging; Debugging is a process where you will checkpoint and run the complete program step by step to understand the flow and error.

Python console gives the ability to run a live command. For example, I have opened a browser, and I Opened Google.com, but I realize I want to open Bing.com, now I do not have to stop the program as I am in the live editor I just change the commands.

Let us see how to open a Live console :


1. Open the Eclipse console.

2. On the Right-hand corner, you can find an icon to like a rectangle with + sign, click it.

3. Choose PyDev Console
pydev-console-selenium

4. Select Console for current Editor
console-for-current-editor

5. Now you have a live console and type the commands that you want to use.
pydev-console-selenium-live

Webdriver Wait in Python Selenium

    About Author :

    I am Pavankumar, Having 8.5 years of experience currently working in Video/Live Analytics project.

    Comment / Suggestion Section
    Point our Mistakes and Post Your Suggestions