What is Selenium (python)?

Selenium automates browsers. That’s it! Selenium follows webdriver protocol i.e. http over wire. What that means is – We can execute commands on a browser by passing GET, POST etc. calls from our scripts. Selenium is a library that comes in various programming languages and here we will be using the python bindings for Selenium. Since selenium is a library/module that goes on python runtime, we will install it through pip (pip is probably the most popular way to install libraries in python). Compare this with bundler in Ruby, Maven/Gradle in Java, npm in node.

The official page for selenium shows the python package as follows:

selenium_python_bindings

The pypi page i.e. from which pip will install selenium-webdriver python module looks as below. You can see that there are sample examples to quickly get you started on the page as well.

pypi_selenium_webdriver

Install selenium-webdriver

Now let’s go ahead and install selenium-webdriver. Open a cmd and run “pip install -U selenium” . The U (upgrade) will get the latest version. After the install goes successfully type “pip list” to list the python modules on your system

Note: I have extra modules like “virtualenv”, “virtualenv-wrapper” etc. You might NOT have those when you first install python, so that is totally fine if you don’t find it in your list

pip_install_selenium

Set up Selenium Components

1) Firefox Browser

Firefox browser DOES NOT require any extra Selenium webdriver components

2) Chrome Browser

a) Download chromedriver.exe from here. Get the latest version

chromedriver1

chromedriver2

b) Unzip chromedriver_win32.zip into C:\SeleniumWebdrivers (assuming you are using windows). The file chromedriver.exe should be present

c) Now add “C:\SeleniumWebdrivers folder to the Windows PATH variable. If you are using Windows 7, go to Control Panel -> Users -> Add/Change environment variables

d) Click ‘New’ under User variables section and do the below

windowspath

e) Verify that chromedriver.exe can be started successfully

chromedriverstarted

f) Hit CTRL+c and kill the process

 

3) Internet Explorer

a) Download IEDriverServer.exe from here. Get the latest version

IEDriver1

IEDriver2

b) Unzip IEDriverServer_Win32_2.44.0.zip [OR 64bit based on your machine] into C:\SeleniumWebdrivers (assuming you are using windows). The file IEDriverServer.exe should be present

c) Now add “C:\SeleniumWebdrivers folder to the Windows PATH variable. If you are using Windows 7, go to Control Panel -> Users -> Add/Change environment variables.

d) Click ‘New’ under User variables section and do the below

Note: Do c) and d) ONLY if you have NOT already done so in chromedriver.exe section above

e) Verify that IEDriverServer.exe can be started successfully

IEDriverStarted

f) Hit CTRL+c and kill the process

Closing Thoughts

At this point, your system has python selenium bindings modules that can be used to write selenium scripts (of course we need more like selenium client components and we will explain that in next few sections)