导包
import yaml
element.yaml
login:
safe: '#element'
link: '#element'
user: ['#element','user1','user2','user3']
password: ['#element','pw']
auth_code: 'element'
code_input: 'element'
enter: 'element'
certificate_enter: 'element'
judge_text: 'element'
test_case.py
# 加载yaml文件
f = open("E:\\xxx\\xxx\\xxx\\element.yaml", encoding="utf-8")
data = yaml.load(f.read(), Loader=yaml.FullLoader)
# 进入登录页面并输入账号密码
value = data['login']
driver.find_element(By.CSS_SELECTOR, value['safe']).click()
driver.find_element(By.CSS_SELECTOR, value['link']).click()
driver.find_element(By.CSS_SELECTOR, value['user'][0]).send_keys(value['user'][1])
driver.find_element(By.CSS_SELECTOR, value['password'][0]).send_keys(value['password'][1])
#输入验证码并登录(需要用到ddddocr库识别验证码)
driver.find_element(By.CSS_SELECTOR, value['code_input']).send_keys(code)
driver.find_element(By.CSS_SELECTOR, value['enter']).click()
driver.find_element(By.CSS_SELECTOR, value['certificate_enter']).click()
#获取断言判断信息
judge_text = driver.find_element(By.CSS_SELECTOR, value['judge_text']).text
标签:python,value,SELECTOR,yaml,pytest,element,find,CSS
From: https://www.cnblogs.com/oytao/p/17663672.html