Tuesday, 16 December 2014

Python bindings for Selenium

Selenium Python binding helps in accessing the Webdriver API, to write the automation scripts using python programming language.
Using Webdriver API, automation scripts can be executed in Firefox, InternetExplorer, etc.

Prerequisites:
1. Python is already installed, click here for python installation.
2. Eclipse IDE is already installed.
3. PyDev extension is installed in Eclipse IDE, click here for installing PyDev extension for Eclipse IDE.

Use 'pip' to install selenium package for python.

Below procedure  demonstrates installing selenium packages in python:

Navigate to 'Scripts' folder present in the python installation folder.


Run command 'pip install selenium' for installing latest selenium package.



Restart the Eclipse IDE, to verify selenium packages are installed.

Verify latest selenium packages are installed:

Click here for additional configuration.

Simple python automation script:
Writing the simple automation script using webdriver api in python.

 '''
Created on 15-Dec-2014

@author:
'''
from selenium import webdriver
from selenium.webdriver.common.keys import Keys

browser = webdriver.Firefox()

browser.get('http://www.google.com')
assert 'Google' in browser.title

# Find the search box
elem = browser.find_element_by_name('q') 
elem.send_keys('seleniumhq' + Keys.RETURN)

browser.quit();

Executing the automation script.
Automation scripts are executed in python language using webdriver api.

1 comment: