def wait_element_available(self, by: str, location: str): wait = WebDriverWait(self.driver, self.timeout) try: element = wait.until(ec.visibility_of_element_located((by, location))) return element except (TimeoutException, NoSuchElementException): logger.error('未找到元素')
def is_clickable(self, by: str, location: str): """ return element if element is clickable else False :param by: xpath, id, name, class with str :param location: //*[@by="location"] :return: """ by = by.lower() try: wait = WebDriverWait(self.driver, self.timeout) element = wait.until(ec.element_to_be_clickable((by, location))) except (TimeoutException, NoSuchElementException): logger.error('元素{}不可点击'.format(location)) else: return element