Reiki 2020-07-28
url="https://www.baidu.com" driver = webdriver.Chrome() driver.get(url) xpath="" #Select元素的Xpath串 ele_sel = driver.find_element_by_xpath(xpath) #获取Select元素对像 select_value = ele_sel.get_attribute(‘value‘) #获取Select选中的值 obj_select = Select(self.CurrentEle) #强制类型转换为Select类型 #遍历Select列表所有选项,根据值反求出选中的文本值 for optio in obj_select.options: if(str(optio.get_attribute(‘value‘))==str(select_value)): result["text"]=str(optio.text) result["val"]=select_value #返回结果 return result
Enjoy :)