python+selenium 元素定位之select下拉选择框

如 有如下代码的下拉选择框

<select id="s-xuan" class="form-control w50" style="float: left;" name="topic_type">
<option selected="selected" value="0">单选题</option>
<option value="1">多选题</option>
<option value="2">文本题</option>


1、导入select库

from selenium.webdriver.support.select import Select

2、实例化,定位

s1 = Select(driver.find_element_by_id("s-xuan"))
s1.select_by_value("1")  
 
 

Select类提供了三种选择某一选项的方法:

select_by_index(index)
select_by_value(value)
select_by_visible_text(text)


猜你喜欢

转载自blog.csdn.net/u011498011/article/details/80029957