获取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()