python_selenium 之yaml文件讀取(以讀取元素信息為例)


一、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)

輸出結果:

 

 

三、實際讀取元素使用:

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM