Selenium 获取Select元素的选中值
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 :)
相关推荐
专注前端开发 2020-10-21
苏康申 2020-11-13
vitasfly 2020-11-12
oraclemch 2020-11-06
liuyang000 2020-09-25
FellowYourHeart 2020-10-05
赵继业 2020-08-17
whyname 2020-08-16
Seandba 2020-08-16
dbasunny 2020-08-16
拼命工作好好玩 2020-08-15
langyue 2020-08-15
写程序的赵童鞋 2020-08-03
Accpcjg 2020-08-02
tydldd 2020-07-30
好记忆也需烂 2020-07-28
jianghero 2020-07-28