[問題]Selenium用Select Class去選多重下拉選單

看板Python作者 (jacobcan118)時間7年前 (2017/04/10 10:26), 編輯推噓0(001)
留言1則, 1人參與, 最新討論串1/4 (看更多)
請問我用python連selenium去做網頁multiple select 想選A, B C值. 但我用下面三種選的方法都可以選到或打開 div的tag看到option. 但在select的變數裡. o.text都是空字串. 我用select.select_by_value("A"), select.select_by_options 都無法選到option. 但是把len(select.options) print出來長度是對的 請問我要怎麼用selenium "Select" class去選那些option? select = Select(driver.find_element_by_xpath('//*[@id="selectName"')) driver.find_element_by_xpath("//*[@id="selectedRoles"]/select") driver.find_element_by_name("selectName") print(select.options) print([o.text for o in select.options]) print(len(select.options)) return len(select.options) <div id = "selectName" role = "listbox" > <select type = "hidden" name = "selectName" multiple = "" > <option value = "" > < / option > <option value = "A" > A < /option > <option value = "B" > B < /option > <option value = "C" > C < /option > < / select > < / div > -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 108.14.0.213 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1491791198.A.09D.html

04/10 16:47, , 1F
你的select變數選到的是<div id="selectName">吧?
04/10 16:47, 1F
文章代碼(AID): #1OwkrU2T (Python)
討論串 (同標題文章)
文章代碼(AID): #1OwkrU2T (Python)