作者jn8029 (鲁)
看板Python
标题Re: [问题]Selenium用Select Class去选多重下拉选单
时间Mon Apr 10 16:50:34 2017
你的select变数选到的是<div id = "selectName">不是<select name="selectName">吧?
用以下这样可行吗?
select = Select(driver.find_element_by_name("selectName"))
select.select_by_value("A")
※ 引述《jacobcan118 (jacobcan118)》之铭言:
: 请问我用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 >
--
○ ○ ◢█████◣ ○ ○ ○
○ ██◤◤◤◤▎ ○ ○
○ ◢█◥██⊙–⊙▏ 炸你全家!!!
██████皿█ ▄▄▄▄▄▄▄ 崖上のboyo
○ ◢█∕█◥██︶◤◤ ○ ○ ○
▂▅▄▆▇ by Airsupply
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 175.182.110.158
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Python/M.1491814237.A.842.html