获取下拉选择框select
<select id="kategorija" name="kategorija">
<option value="0">Kategorija</option>
<option value="12">Vijesti</option>
<option value="8">Biznis</option>
</select>
可以这样定位
import time
from selenium import webdriver
from selenium.webdriver.support.select import Select
driver = webdriver.PhantomJS()
# driver = webdriver.Chrome()
url = 'xxxx'
driver.set_window_size(800, 600) # 对于Phantomjs记得加上这个要不然会出错
driver.get(url)
time.sleep(3)
select = Select(driver.find_element_by_id("kategorija")) # 实例化select
select.select_by_value('0') # 选择第1项选项:value='0'
select.select_by_index(2) # 选择第2项选项 从1开始
select.select_by_visible_text('Biznis') # 选择第3项选项:Biznis
网友评论