您的位置:首页 > 编程语言 > Python开发

python 遍历select的option选项

2016-06-12 09:36 357 查看
 <html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

<title>获取option的值和文本</title>

</head>

<body>

<form>

<select id="ss">

<option value="1111">aaa</option>

<option value="2222">bbb</option>

<option value="3333">ccc</option>

<option value="4444">ddd</option>

</select>

</form>

<script type="text/javascript">

var oSelect=document.getElementByIdx_x_x("ss");

oSelect.onchange=function(){                                       //当选项改变时触发

     var valOption=this.options[this.selectedIndex].value;//获取option的value

     alert(valOption);

     var txtOption=this.options[this.selectedIndex].innerHTML;//获取option中间的文本

      alert(txtOption);

}

</script>

</body>

</html>

----------------------------------------------------------------------------------------------------------------------------------------

# coding:utf-8

from selenium import webdriver

browser = webdriver.Firefox()

url = 'file:///C:/Users/liqq/Desktop/option.html'

browser.get(url)

select = browser.find_element_by_id("ss")

options_list = select.find_elements_by_tag_name("option")

count = 0

for option in options_list:

    print "Value is: " + option.get_attribute("value")

    print "Text is:" + option.text

#    count = count + 1

#    print count
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python 遍历 select