方法①(记得返回值):
feature = (By.XPATH, check_param(path='主页性别-勾选框', param=param))
return self.select_state(feature)
方法②(记得返回值):
feature = (By.XPATH, (ele['主页性别-勾选框'].format(param)))
return self.select_state(feature)
方法③(记得返回值):
target = ele['主页性别-勾选框'].format(param)
return self.find_el((By.XPATH, target)).is_selected()
def check_param(path, param=None):
''' 用于检验传过来的值 '''
if param is not None:
# 传过来的值是不是List
if isinstance(param, list):
value = ele[path].format(*param)
else:
value = ele[path].format(str(param))
else:
value = ele[path]
return value
def select_state(self, feature):
''' 是否被选中 '''
return self.find_element(feature).is_selected()
def find_element(self, feature):
by, value = feature
try:
return WebDriverWait(self.driver, self.timeout).until(
EC.presence_of_element_located((by, value)))
except(NoSuchElementException, TimeoutException):
logging.error("No Such Element:" + value)