作者yshihyu (yshihyu)
看板Python
标题[问题] Selenium 用 Select 选出下拉选单
时间Mon Apr 23 13:37:07 2018
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://webptt.com/cn.aspx?n=bbs/Python/M.1524461833.A.478.html
1F:推 victor0929: 用xpath? 04/24 17:59
2F:→ s860134: 这个是某家 router 的控制介面吧? 04/24 23:26
3F:→ s860134: 其实你可以直接用 execute_script 直接对那个栏位操作... 04/24 23:27
4F:推 rexyeah: 试试select_by_value() 而且你的select display:none ? 04/25 14:51
5F:推 asglay: 先用requests读出来, 再用beautifulsoup parsing出来 04/25 22:59
6F:→ yshihyu: select_by_value 试过不行 ... select display直接是none 04/25 23:36
7F:→ yshihyu: 找到原因了~要先用 execute_script把 display:设成block 04/25 23:45
8F:→ yshihyu: 在用select 就可以~感谢 04/25 23:45