获取ul下面最后一个li或ul中有多少个li
Posted 安
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了获取ul下面最后一个li或ul中有多少个li相关的知识,希望对你有一定的参考价值。
获取ul下面最后一个li或ul中有多少个li
先获取ul的对象,再通过这个对象获取li的list用for循环取值text之类的
def set_city(self, base_info): qualified_city = base_info[‘qualified_city_input‘] if ‘全国‘ in qualified_city.keys(): self.get_element(‘china_checkbox‘).click() else: self.get_element(‘qualified_city_unfold_button‘).click() # 点击城市按钮 provinces = self.get_element_list(‘places_checkbox‘) # 获取全部城市 知识点 for province in provinces: province_name = province.find_element_by_css_selector(‘.ivu-tree-title‘).text # 获取城市的名字 # print(province_name) if province_name in qualified_city.keys(): citys = qualified_city[province_name] # print(citys) if not citys: province.find_element_by_css_selector(‘.ivu-checkbox-input‘).click() # 知识点 else: province.find_element_by_css_selector(‘.ivu-tree-arrow‘).click() city_eles = province.find_elements_by_css_selector(‘li > ul‘) for city_ele in city_eles: city_name = city_ele.find_element_by_css_selector(‘.ivu-tree-title‘).text if city_name in citys: print(city_name) city_ele.find_element_by_css_selector(‘.ivu-checkbox-input‘).click()
以上是关于获取ul下面最后一个li或ul中有多少个li的主要内容,如果未能解决你的问题,请参考以下文章