The overall framework, first divided into small functional modules ~ ~, from the simplest start, introduction
Implementation of the cycle Baidu search Example:
#coding =utf-8
‘‘‘
Created on 2014?? 6?? 9??
@author: Small Fish
‘‘‘
Import xlrd
From selenium import Webdriver
Import time
#excelFile文件物理地址
Book=xlrd.open_workbook ("E:\Users\Administrator\workspace\SeleniumTest\excelFile.xls")
Browser = Webdriver. Firefox ()
Browser.get ("http://www.baidu.com/")
Time.sleep (3)
#实现百度输入搜索内容
def select (a):
browser.find_element_by_id ("Kw1"). Send_keys (a)
Time.sleep (2)
browser.find_element_by_id ("SU1"). Click ();
Browser.back ()
Time.sleep (1)
def excelfile (x, Y, z):
Sheel_name = Book.sheet_by_name (x)
Cell_value = Sheel_name.cell_value (y,z)
Return Cell_value
def excelrows (x):
Sheel_name = Book.sheet_by_name (x)
Nrows=sheel_name.nrows
Return nrows
def EXCELCOLSS (x):
Sheel_name = Book.sheet_by_name (x)
Cols=sheel_name.ncols
return cols
rows = Excelrows ("Baidu")
cols = EXCELCOLSS ("Baidu")
#循环读取excel文件内容
for R in range (0,rows):
I =0
Select (Excelfile ("Baidu", R,i))
Print "Search content:%s"%excelfile ("Baidu", R,i)
I=i+1
Print "Loop to read Excel file End"
Browser.close ()
Browser.quit ()
Web automation Framework Building II Simple example of data-driven application ~ ~