Web automation Framework Building II Simple example of data-driven application ~ ~

Source: Internet
Author: User

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 ~ ~

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.