定位元素操作

   # - * -编码:utf - 8 - *   #=2019/5/13日期   # name=" yedeng "   # project_name=python   解释:从yaml文件中读取返回webelement      进口yaml   从selenium.webdriver.remote。webdriver进口webdriver   从selenium.webdriver.support。等进口WebDriverWait   从selenium.webdriver.remote。webelement进口webelement   从selenium.webdriver。支持导入expected_conditions EC   从selenium.common.exceptions进口TimeoutException      从跑龙套。FindWebElemet进口FindWebElement   从跑龙套。将其作为FindBy FindBy进口   从跑龙套。日志导入日志   从跑龙套。ReadIni进口ReadIni      # yaml文件位置   #读入读取配置文件中的等待时间   “‘   初始化添加对应的yaml文件位置,然后调用getAllValue方法,调用getelement方法获取到对应的webelement   改进方法:保证yaml的文件名和test_case的文件名或者类名一致   “‘         类ReadyamlToElement:   #获取当前脚本所在文件夹路径      def __init__(自我,司机:WebDriver yamlpath):   ”“”   实例化readyaml类   :param司机:   :param yamlpath:对应的yaml文件名   ”“”   自我。__yamlPath=yamlpath   自我。__driver=司机      def __getAllValue(自我):   ”“”   将指定yaml文件转化为dic字典,为关键   :返回dic字典   ”“”   “‘   curPath=os.path.dirname (os.path.realpath (__file__))   #获取yaml文件路径   yamlPath=os.path。加入(curPath“cfgyaml.yaml”)   print(类型(yamlPath))   “‘   打开(自我。__yamlPath,‘r’,编码=f“utf - 8”):   cfg=f.read ()      dic_yaml=yaml。负载(cfg,装载机=yaml.FullLoader) #用负载方法转字典   返回dic_yaml      “‘   通过关键获取到对应的webelement,改进方法,将其全部遍历后,生成关键:元素的字典,从里面取对应的数据   “‘      def getelement(自我,键)→WebElement:   ”“”   通过yaml文件的关键获取到对应的Webelement   :param关键:yaml文件的关键   返回:对应的WebElement对象   :rtype keyelement: selenium.webdriver.remote.webelement   ”“”   dic=ReadyamlToElement(自我。__driver self.__yamlPath) .__getAllValue() #接受readyaml () .getAllValue()返回的东西   #打印(dic)   如果dic的关键之处:   list_value=https://www.yisu.com/zixun/dic.get(键)   # list_Type_value=list_value [0] .split(“:”)[1] #获取类型的值   # list_Value_value=https://www.yisu.com/zixun/list_value [1] .split(“:”)[1] #获取值的值   list_Type_value=https://www.yisu.com/zixun/list_value.get(“类型”)#获取类型的值   list_Value_value=https://www.yisu.com/zixun/list_value.get(“价值”)#获取值的值   keyelement=FindWebElement(自我。__driver list_Type_value,   list_Value_value) .find_element(自我。__yamlPath,键)#用于返回webelement对象   Log.info (self.__yamlPath +”中获取到该元素,通过该关键:“+键)   返回keyelement   其他:   Log.error(自我。__yamlPath +”中不存在该关键:“+键+”:关闭程序”)   # self.__driver.quit ()      def getelements(自我,键)→列表:   ”“”   通过yaml文件的关键获取到对应的Webelement   :param关键:yaml文件的关键   返回:对应的WebElement对象类型为WebElement   :rtype keyelements:列表   ”“”   dic=ReadyamlToElement(自我。__driver self.__yamlPath) .__getAllValue() #接受readyaml () .getAllValue()返回的东西   #打印(dic)   如果dic的关键之处:   list_value=https://www.yisu.com/zixun/dic.get(键)   # list_Type_value=list_value [0] .split(“:”)[1] #获取类型的值   # list_Value_value=https://www.yisu.com/zixun/list_value [1] .split(“:”)[1] #获取值的值   list_Type_value=https://www.yisu.com/zixun/list_value.get(“类型”)#获取类型的值   list_Value_value=https://www.yisu.com/zixun/list_value.get(“价值”)#获取值的值   keyelementlist=FindWebElement(自我。__driver list_Type_value,   list_Value_value) .find_elements(自我。__yamlPath,键)#用于返回webelement对象   Log.info (self.__yamlPath +”中获取到该元素,通过该关键:“+键)   返回keyelementlist   其他:   Log.error(自我。__yamlPath +”中不存在该关键:“+键+”:关闭程序”)   # self.__driver.quit ()      def getelementsintnum(自我,关键,intnum=0)→WebElement:   ”“”   通过yaml文件的关键获取一组WebElemnts,通过数组下标获取对应的WebElemnt   :param关键:yaml文件的关键   :param intnum数组下标   :关键类型:字符串   :类型intnum: int   返回:对应的WebElement对象   :rtype keyelements [intnum]: selenium.webdriver.remote.webelement   ”“”   dic=ReadyamlToElement(自我。__driver self.__yamlPath) .__getAllValue() #接受readyaml () .getAllValue()返回的东西   #打印(dic)   list_keyelements=[]   如果dic的关键之处:   list_value=https://www.yisu.com/zixun/dic.get(键)   # list_Type_value=list_value [0] .split(“:”)[1] #获取类型的值   # list_Value_value=https://www.yisu.com/zixun/list_value [1] .split(“:”)[1] #获取值的值   list_Type_value=https://www.yisu.com/zixun/list_value.get(“类型”)#获取类型的值   list_Value_value=https://www.yisu.com/zixun/list_value.get(“价值”)#获取值的值   list_keyelements=FindWebElement(自我。__driver list_Type_value,   list_Value_value) .find_elements(自我。__yamlPath,键)#用于返回webelement对象   Log.info (self.__yamlPath +”中获取到该元素,通过该关键:“+键)   其他:   Log.error(自我。__yamlPath +”中不存在该关键:“+键+”:关闭程序”)   # self.__driver.quit ()   #判断输入的值是否正确,正确则正确找到,否则就报空   如果len (list_keyelements) & lt;=intnum & lt;len (list_keyelements):   返回list_keyelements [intnum]   其他:   日志。错误(“当前输入的intnum大于“+ str (len (list_keyelements)) +“有问题”)   回来没有      def getelementsstringtext(自我、关键strtext: str, attributename=None)→WebElement:   ”“”   通过yaml文件的关键获取一组WebElemnts,通过指定元素的值获取到对应的WebElemnt   :param关键:yaml文件的关键   :param strtext对应元素的值   :关键类型:str   :类型strtext: str   :param attributename元素的属性值,属性/属性的名称来检索   :类型attributename: str   返回:对应的WebElement对象   :rtype元素:selenium.webdriver.remote.webelement   ”“”   dic=ReadyamlToElement(自我。null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null

定位元素操作