<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<title>定位网页元素</title>
</head>

<body>

<p>选择您喜爱的车</p>
<select id="multi" multiple>
<option value="benz">奔驰S300</option>
<option value="accord">雅阁</option>
<option value="bmw" selected="selected">宝马 740</option>
<option value="audi">奥迪A6</option>
</select>

<hr>

<p>选择性别</p>
<select id="single">
<option value="male">男</option>
<option value="female" selected="selected">女</option>
</select>

</body>
</html>

###################################################
# coding=utf-8
from selenium import webdriver

driver = webdriver.Chrome(r"d:\tools\webdrivers\chromedriver.exe")

driver.get('file:///E:/package/code/selenium/code/lesson04/ms.html') # 打开网址

# 导入 Select
from selenium.webdriver.support.ui import Select
# 获得相应的WebElement
select = Select(driver.find_element_by_id("multi"))
# 先去选择所有的 选项
select.deselect_all() # 取消已选择的
select.select_by_visible_text("雅阁")
select.select_by_visible_text("宝马 740")

# 获得相应的WebElement
select = Select(driver.find_element_by_id("single"))
select.select_by_visible_text("男")

input('press any key to quit...')
driver.quit() # 浏览器退出