def find_element(self, element_info): locator_type_name = element_info['locator_type'] locator_value_info = element_info['locator_value'] locator_timeout = element_info['timeout'] if locator_type_name == 'id': locator_type = By.ID elif locator_type_name == 'name': locator_type = By.NAME elif locator_type_name == 'class': locator_type = By.CLASS_NAME elif locator_type_name == 'xpath': locator_type = By.XPATH element = WebDriverWait(self.driver , locator_timeout)\ .until(lambda x:x.find_element(locator_type,locator_value_info)) logger.info('[%s]元素识别成功' % element_info['element_name']) # element = WebDriverWait(self.driver, locator_timeout)\ # .until(EC.presence_of_element_located((locator_type, locator_value_info))) return element
def get_username(self): value = self.username_showspan.text logger.info('获取用户名成功,用户名是:' + str(value) ) return value
def input(self, element_info, content): element = self.find_element(element_info) element.send_keys(content) logger.info('[%s]元素输入内容:%s' % (element_info['element_name'], content))
def click(self, element_info): element = self.find_element(element_info) element.click() logger.info('[%s]元素进行点击操作' % element_info['element_name'])
def get_title(self): value = self.driver.title logger.info('获取网页标题,标题是%s' % value) return value
def refresh(self): self.driver.refresh() logger.info('浏览器刷新操作')
def set_browser_min(self): self.driver.minimize_window() logger.info('设置浏览器最小化')
def set_browser_max(self): self.driver.maximize_window() logger.info('设置浏览器最大化')
def open_url(self, url): self.driver.get(url) logger.info('打开url地址 %s ' % url)