import xlrd
import time
import unittest
from selenium import webdriver class u8819(unittest.TestCase):
global loginurl
global driverpath
loginurl = 'http://www.effevo.com'
driverpath = 'D:\\chromedriver.exe'
userpath = 'D:\\data.xlsx' #获取data.xlsx中的用户数据(用户名密码)
def open_excel(self, file = userpath, rownameindex = 0, table = '用户表'):
try:
self.data = xlrd.open_workbook(file)
self.table = self.data.sheet_by_name(table)
self.colnames = self.table.row_values(rownameindex) #找到列名 默认第一行为列名
self.nrows = self.table.nrows
       list = [] 
for rownum in range(1, self.nrows):
rowvalue = self.table.row_values(rownum) if rowvalue:
user = {}
for i in range(len(rowvalue)):
user[self.colnames[i]] = rowvalue[i]
list.append(user)
print(list)
return list
except Exception:
print('文件未发现:' + file)    #获取excel的用户名密码登陆  
def login(self):
listdata = self.open_excel()
#if(len(listdata) < 0 ):
# assert 0, u"Excel数据异常:无数据" for i in range(len(listdata)):
self.driver = webdriver.Chrome(driverpath)
self.driver.get(loginurl)
assert "工作云" in self.driver.title self.driver.find_element_by_xpath(".//*[@id='home']/div/div[2]/header/nav/div[3]/ul/li[1]/a").click()
time.sleep(5) self.driver.find_element_by_xpath(".//*[@id='passname']").clear()
self.driver.find_element_by_xpath(".//*[@id='passname']").send_keys(str(listdata[i]['username']))
self.driver.find_element_by_xpath(".//*[@id='password']").clear()
self.driver.find_element_by_xpath(".//*[@id='password']").send_keys(listdata[i]['password'])
self.driver.find_element_by_xpath(".//*[@id='content']/div/div[6]/input").click() a = u8819()
a.login() if __name__ == '__main__':
unittest.main() 来源:https://www.cnblogs.com/insane-Mr-Li/p/9093212.html

最新文章

  1. Mybatis3.x与Spring4.x整合(转)
  2. 为什么上传文件的表单里面要加一个属性enctype=multipart/form-data?
  3. VES Hand Book Contents
  4. iOS中线程同步基本详解
  5. Python面试题(一)
  6. c#重点[集合类型]异常,数组,集合ArrayList,List&lt;&gt;,hashTable,hashtable泛型(Dictionary)
  7. 【转】CSS(10)盒子模型
  8. 安装max plugin wizard
  9. Coder-Strike 2014 - Finals (online edition, Div. 2) C题
  10. Nginx安装及配置简介
  11. 基于RMAN从活动数据库异机克隆(rman duplicate from active DB)
  12. Unity SendMessage方法
  13. bin home
  14. KingbaseES的HA搭建
  15. [日常] HTTP的媒体类型
  16. cmake mac 安装
  17. C++STL deque
  18. 洛谷P3248 [HNOI2016]树(主席树 倍增 )
  19. JVM,Java虚拟机基础知识新手入门教程(超级通熟易懂)
  20. Oracle ORA12514 监听程序当前无法识别连接描述符中请求的服务

热门文章

  1. 几种new
  2. Struts2 动态结果集
  3. SQL Server中如何设置对列的权限
  4. arcgis server10.2.2公布地图基础服务的详细步骤
  5. win7配置免安装mysql5.6.19过程具体解释
  6. Linux - 文件查找方法
  7. 【NOIP 2011】 计算系数
  8. c#为程序添加全局热键的方法
  9. k8s istio 配置请求的路由规则
  10. 康少带你玩转JavaScript