环境搭建:
需要配置WebTours网站
'''
读取Text文档数据
'''
# 导入包
from selenium import webdriver
from selenium.webdriver.support.select import Select
from time import sleep
# 打开浏览器
driver = webdriver.Chrome()
# webdriver.Ie()
# webdriver.Firefox()
file = open('user.txt','r')
# for x in file:
# # print (x,end='')
# a = x.split()
# print(a[0]+' ' +a[1])
a = file.readlines()
for i in range(0,len(a)):
x = a[i].split()
yhm = x[0]
print(yhm)
mm=x[1]
print(mm)
# 打开网址
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 = "Thank you, "+yhm
actual = driver.find_element_by_tag_name("body").text
print(actual)
# 精确匹配用in 否则用in
if expect in actual:
print("pass")
else:
print("fail")
driver.quit()
file.close()