该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
#创建基础类
class BasePage(object):
#初始化
def __init__(self, driver):
self.base_url = 'https://mail.qq.com/'
self.driver = driver
self.timeout = 30
#定义打开登录页面方法
def _open(self):
url = self.base_url
self.driver.get(url)
self.driver.switch_to.frame('login_frame') #切换到登录窗口的iframe
#定义定义open方法,调用_open()进行打开
def open(self):
self._open()
#定位方法封装
def find_element(self,*loc):
return self.driver.find_element(*loc)
#创建LoginPage类
class LoginPage(BasePage):
username_loc = (By.ID, "u")
password_loc = (By.ID, "p")
login_loc = (By.ID, "login_button")
#输入用户名
def type_username(self,username):
self.find_element(*self.username_loc).clear()
self.find_element(*self.username_loc).send_keys(username)
#输入密码
def type_password(self,password):
self.find_element(*self.password_loc).send_keys(password)
#点击登录
def type_login(self):
self.find_element(*self.login_loc).click()