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

看板Python作者 (jacobcan118)時間7年前 (2017/04/11 02:30), 編輯推噓0(004)
留言4則, 2人參與, 最新討論串3/4 (看更多)
不行. 可以選到element但是select.options的值還是空的. 用select.select_by_value("A")會有 selenium.common.exceptions.ElementNotVisibleException: Message: element not visible: Element is not currently visible and may not be manipulated 錯誤 ※ 引述《jn8029 (魯)》之銘言: : 你的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 > -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 108.14.0.213 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1491849017.A.56A.html

04/11 08:42, , 1F
有網址嗎? 我剛隨便用另一個網頁這樣做可以選到耶
04/11 08:42, 1F

04/11 10:20, , 2F

04/11 10:21, , 3F
點像link裡的multiselect 有input欄位,點選後選單會
04/11 10:21, 3F

04/11 10:23, , 4F
出現,但是我的option分別包在select 和另一個div裡
04/11 10:23, 4F
文章代碼(AID): #1OwyyvLg (Python)
討論串 (同標題文章)
文章代碼(AID): #1OwyyvLg (Python)