from time import sleep
from selenium import webdriver
from selenium.webdriver.support.select import select
driver = webdriver.chrome(
)# driver.maximize_window()
driver.implicitly_wait(10)
driver.get(
"url"
)driver.find_element_by_css_selector(
).click(
)driver.find_element_by_xpath(
'//*[@id="head"]/div[1]/div/div[2]/div/ul/li/ul/li[2]/a'
).click(
)ele = driver.find_element_by_xpath(
'//*[@id="s_province"]'
)a = select(ele)
.options #獲得所有下拉框的元素p=-
1for i in a :
p +=
1#定義變數充當索引
(i.text)
#將元素轉化為具體的下拉框選項值
select(ele)
.select_by_index(p)
#根據索引選中對應專案
elp = driver.find_element_by_xpath(
'//*[@id="s_city"]'
) s=-1
b = select(elp)
.options
for j in b :
s +=
1print
(j.text)
iflen
(b)#防止索引超過最大值
continue
else
: select(elp)
.select_by_index(s)
# driver.find_element_by_xpath('//*[@id="s_province"]/option[2]').click()
sleep(10)
driver.quit(
)
自己總結封裝了多級聯動下拉框js
支援多級下拉框 data 查詢出來的所有資料,經過處理縮排的多級資料。子集用固定child,pdata 選中的資料。字串用逗號隔開例 4,57,557 如果沒有就空字串 author 1017361009 qq.com 歡迎優化改進 function son eval pjsons if son f...
python下拉框二級聯動 antd下拉框聯動說明
先說一下效果要求,上面乙個下拉框,下面乙個,要求上面選中的時候,下面的內容要跟著變。因為想到react是資料驅動的,就不打算再用jq的那種隱藏顯示了,而是通過在執行型別下拉框的onchange事件中,去改變下面的下拉框的資料,渲染出不同的下拉選擇。定義資料 modeoptions是各個下拉框的值,由...
下拉框聯動
這裡寫了selclass和sellesson兩個下拉框,下拉框的selclass的選中值事件會觸發addsellesson 方法,該方法通過ajax向後台非同步請求資料動態給下拉框sellesson賦值 html 如下 班級課程 selclass onchange addsellesson styl...