#下拉框多选操作
import unittest
import time
from selenium import webdriver
class VisitSogouByIE(unittest.TestCase):
def setUp(self):
# 启动IE浏览器
self.driver = webdriver.Ie(executable_path="g:\\IEDriverServer")
def test_operateMultipleOptionDropList(self):
url = "http://127.0.0.1/test_multiple_select.html"
# 访问自定义的html网页
self.driver.get(url)
# 导入Select模块
from selenium.webdriver.support.ui import Select
# 使用xpath定位方式获取select页面元素对象
select_element = Select(self.driver.find_element_by_xpath("//select"))
# 通过序号选择第一个元素
select_element.select_by_index(0)
# 通过选项的文本选择“山楂”选项
select_element.select_by_visible_text("山楂")
# 通过选项的value属性值选择value=“mihoutao”的选项
select_element.select_by_value("mihoutao")
# 打印所有的选中项文本
for option in select_element.all_selected_options: