0. Getting Started with Selenium

Getting Started:

1. Install python version 2.7 32-Bit in your Computer Machine:

2. Install easy_install for python 2.7 32-Bit in your Computer Machine
3. Edit your system path variables as C:\Python27;C:\Python27\Scripts .
Watch the Video how to Set your computer machine system path in windows 8:

4. Run cmd in your windows and type easy_install selenium. It will install selenium package inside your python/site-packages folder and you are ready to for running a selenium program

Starting with a simple selenium example:

 


from selenium import webdriver
import time 
 
driver = webdriver.Firefox()
driver.get("http://www.youtube.com/watch?v=AwzOw9MayeE")
time.sleep(25)
driver.close()

python youtube.py

NOTE: You have to type above statement in cmd 

Explanation:
The first line import webdriver module from selenium package. This is a standard way to import a module in python.

Second line import time library from python module which have some in built function for python like time.sleep().

Third line gets an object for webdriver.Firefox() inside driver variable which will be used for future reference call to browser Firefox. Firefox() will launch the firefox web browser.

NOTE: If you don't have installed Firefox install it in your computer machine
Fourth line driver.get method will navigate to a page given by the URL. WebDriver will wait until the page has fully loaded (that is, the “onload” event has fired) before returning control to your test or script. It’s worth noting that if your page uses a lot of AJAX on load then WebDriver may not know when it has completely loaded.   

Fifth Line time.sleep(25)  makes the program to sleep for 25 seconds and at last sixth line browser quits.


No comments: