1、按照索引
2、按照value值的方式
3、按照文本的方式
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body bgcolor="pink">
<center>
<select id="name" width="100px" height="50px">
<option value="go">go语言</option>
<option value="python">python语言</option>
</select>
</center>
</body>
</html>
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
import time as t
driver=webdriver.Chrome()
driver.maximize_window()
driver.get('file:///C:/Users/29660/PycharmProjects/pythonProject/UI%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95/xialakuang.html')
selectID=driver.find_element(By.ID,'name')
select=Select(selectID)
t.sleep(3)
# 按照索引
# select.select_by_index(1)
# 按照value值的方式
# select.select_by_value('python')
# # 按照文本的方式
select.select_by_visible_text('python语言')
t.sleep(3)
driver.quit()
下拉框练习
driver=webdriver.Chrome()
driver.maximize_window()
driver.get('https://www.lagou.com/')
t.sleep(3)
driver.find_element(By.ID,'cboxClose').click()
t.sleep(3)
driver.find_element(By.ID,'search_input').send_keys('测试开发工程师')
t.sleep(3)
driver.find_element(By.ID,'search_button').click()
t.sleep(3)
# 点击学历
driver.find_element(By.XPATH,'/html/body/div/div[2]/div/div[2]/div[1]/div[1]/div[2]/div/ul/li[2]/div').click()
t.sleep(3)
driver.find_element(By.XPATH,'/html/body/div/div[2]/div/div[2]/div[1]/div[1]/div[2]/div/ul/li[2]/div/div/ul[2]/li[1]/span').click()
t.sleep(3)
driver.quit()