获取字典某一层的值
"""
获取yaml文件中的字典value值,可获取字典值任意一层
ele_dict = {
'password_input':
{
'dec': '登录按钮',
'type': 'XPATH',
'value': '//button'
},
'account_number_input':
{
'dec': '账号输入框',
'type': 'CLASS_NAME',
'value': 'ivu-input',
'index': 0
},
}
"""
def get_value(self, *keys):
"""
@param keys:yaml文件中的key值,可多层,['password_input','dec']或者['password_input']
@return: 返回字典中value值
"""
try:
ele_dict = yaml.load(self.cfg, Loader=yaml.FullLoader) # 用load方法转字典
print(ele_dict)
if not keys:
return ele_dict
else:
for key in keys:
tmp = ele_dict.get(key)
if tmp is not None:
ele_dict = tmp
return ele_dict