如题,这是我写的登录脚本
@file_data('zentao_login.yaml')
def test_login(self, user, pwd, status):
account = user
password = pwd
# 元素定位:分别是用户名输入框、密码输入框、登录按钮
user_loc = self.driver.find_element(By.XPATH, '//*[@id="account"]')
pwd_loc = self.driver.find_element(By.XPATH, '//*[@id="login-form"]/form/table/tbody/tr[2]/td/input')
btn_loc = self.driver.find_element(By.XPATH, '//*[@id="submit"]')
# 判断状态: 0为正确用户名密码 1为不正确用户名密码
if status == '0':
# 给元素传值
user_loc.send_keys(account)
pwd_loc.send_keys(password)
# 点击登录
btn_loc.click()
print(self.driver.title, self.driver.current_url)
self.assertEqual('my', self.driver.current_url)
self.assertIn('我的地盘', self.driver.title)
elif status == '1':
# 给元素传值
user_loc.send_keys(account)
pwd_loc.send_keys(password)
# 点击登录
btn_loc.click()
print(self.driver.title, self.driver.current_url)
# print(self.driver.switch_to.alert.text)
self.driver.switch_to.alert.accept()
sleep(3)
else:
print('参数化的状态只能传入0或1')
这是执行后的结果:
两个问题:
一、为什么成功登录之后(执行过程中已经看到登录之后的页面了而且能看到页面的url也是登录之后的url),获取到的URL还是登录页面的URL
二、上图2的Error为啥会报错?下图是错误用户名密码登录后弹出的警告框