[問題] Selenium 用 Select 選出下拉選單

看板Python作者 (yshihyu)時間7年前 (2018/04/23 13:37), 編輯推噓3(305)
留言8則, 5人參與, 7年前最新討論串1/1
https://imgur.com/a/ALoXGnR // 像是這樣下拉選單 下面程式碼我想選擇第7個頻道 select = Select(driver.find_element_by_name("channel_24")) select.select_by_visible_text("7") for op in select.options: print(op.text) 我程式碼印出來的下單選單都是空的~ 錯誤: selenium.common.exceptions.ElementNotVisibleException: Message: element not visible: Element is not currently visible and may not be manipulated 下面網址是我要用Select 讀取的 html 跟 下面是完整的錯誤訊息 https://gist.github.com/shihyu/d41512962cb35dea2dd8c369bdb0154b 因為我試過很多方式都無法選擇要的欄位 謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 175.181.253.178 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1524461833.A.478.html

04/24 17:59, 7年前 , 1F
用xpath?
04/24 17:59, 1F

04/24 23:26, 7年前 , 2F
這個是某家 router 的控制介面吧?
04/24 23:26, 2F

04/24 23:27, 7年前 , 3F
其實你可以直接用 execute_script 直接對那個欄位操作...
04/24 23:27, 3F

04/25 14:51, 7年前 , 4F
試試select_by_value() 而且你的select display:none ?
04/25 14:51, 4F

04/25 22:59, 7年前 , 5F
先用requests讀出來, 再用beautifulsoup parsing出來
04/25 22:59, 5F

04/25 23:36, 7年前 , 6F
select_by_value 試過不行 ... select display直接是none
04/25 23:36, 6F

04/25 23:45, 7年前 , 7F
找到原因了~要先用 execute_script把 display:設成block
04/25 23:45, 7F

04/25 23:45, 7年前 , 8F
在用select 就可以~感謝
04/25 23:45, 8F
文章代碼(AID): #1QtN49Hu (Python)
文章代碼(AID): #1QtN49Hu (Python)