环境搭建:
1.需要配置WebTours网站
2.安装pandas
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple numpy
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pandas
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple python_dateutil
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pytz
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple six
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple xlrd
3.
实现代码
#cases.xls
# skiprows=1 默认跳过第一行
# print(data)
'''
读取excal文档数据
'''
# 导入包
from selenium import webdriver
from selenium.webdriver.support.select import Select
from time import sleep
import pandas
# 打开浏览器
driver = webdriver.Chrome()
# webdriver.Ie()
# webdriver.Firefox()
data = pandas.read_excel('user.xlsx', header=None, names=['yhm','mm','yq'],dtype={'yhm':str,'mm':str,'qy':str})
datalist = data.values.tolist()
for x in datalist:
yhm = x[0]
print(yhm)
mm=x[1]
print(mm)
yq = x[2]
print(yq)
# 打开网址
driver.get("http://127.0.0.1:1080/WebTours/")
# 等待3秒
sleep(3)
# 关闭浏览器
# driver.close()
#关闭浏览器 及驱动
# 切换框架
driver.switch_to_default_content()
driver.switch_to_frame("body")
driver.switch_to_frame("info")
driver.find_element_by_link_text("sign up now").click()
sleep(3)
# 跳转页面,还是需要切换框架
driver.switch_to_default_content()
driver.switch_to_frame("body")
driver.switch_to_frame("info")
driver.find_element_by_name("username").send_keys(yhm)
driver.find_element_by_name("password").send_keys(mm)
driver.find_element_by_name("passwordConfirm").send_keys(mm)
driver.find_element_by_name("register").click()
sleep(3)
# 跳转页面,还是需要切换框架
driver.switch_to_default_content()
driver.switch_to_frame("body")
driver.switch_to_frame("info")
expect = yq
actual = driver.find_element_by_tag_name("body").text
print(actual)
# 精确匹配用in 否则用in
if expect in actual:
print("pass")
else:
print("fail")
driver.quit()