[問題]Selenium用Select Class去選多重下拉選單
請問我用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
04/10 16:47, 1F
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 4 篇):