首页 > 编程语言 > 详细

python_selenium 之yaml文件读取(以读取元素信息为例)

时间:2020-05-07 00:25:43      阅读:614      评论:0      收藏:0      [点我收藏+]

一、yaml源文件编写

技术分享图片

 

 

 

二、对yaml文件内容的读取

#coding=gbk
import os
import yaml

current_path=os.path.dirname(__file__)
yaml_path=os.path.join(current_path,‘../element_info_datas/element_login_infos.yaml‘)

class ElementdataYamlUtils():

def get_yaml_element_info(self,yaml_path):
file = open(yaml_path, ‘r‘, encoding="gbk")
file_data = file.read()
file.close()
# 指定Loader
data = yaml.load(file_data, Loader=yaml.FullLoader)
return data

if __name__ == ‘__main__‘:
current_path = os.path.dirname(__file__)
yaml_path = os.path.join(current_path, ‘../element_info_datas/element_login_infos.yaml‘)
elements=ElementdataYamlUtils().get_yaml_element_info(yaml_path)
for e in elements.values():
print(e)

输出结果:

技术分享图片

 

 

三、实际读取元素使用:

技术分享图片

 

python_selenium 之yaml文件读取(以读取元素信息为例)

原文:https://www.cnblogs.com/123anqier-blog/p/12839985.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!