不要定义内部的每个元素
__init__
,请尝试使用以下内容:
@property
def getusernametextbox(self):
return Browser.webDriverWait.until(ec.visibility_of_element_located((By.ID, "login_email")))
@property
def getpasswordtextbox(self):
return Browser.webDriverWait.until(ec.visibility_of_element_located((By.CSS_SELECTOR, "tr[id=mockpass] input")))
@property
def getloginbutton(self):
return Browser.webDriverWait.until(ec.element_to_be_clickable((By.NAME, "login")))
def login(self):
self.getusernametextbox.send_keys("myuser@gmail.com")
self.getpasswordtextbox.send_keys("12345678")
self.getloginbutton.click()