python - 如何使用 Python 和 Selenium Webdriver 使用 mat-options 查找下拉列表的长度?

标签 python selenium selenium-webdriver

我正在处理使用 Angular JS 创建的下拉菜单。当我查看 HTML 时,我看到的下拉选项有一个标签,而不是标准的 .因此,当我尝试计算下拉长度时,以下标准方法不起作用

 select = drowser.find_element_by_id(elementID))
 print len(select.options)

我还能如何尝试找出我的下拉菜单有多少个选项?

已编辑:以下是 HTML 示例:

enter image description here

最佳答案

您的元素不是 HTML select 标记,并且无法在其上使用 Selenium 的 Select 类。相反,获取 div.mat-select-content 下带有 mat-option 标签的所有元素:

 selectOptions = drowser.find_elements_by_css_selector("div.mat-select-content mat-option")
 print len(selectOptions)

关于python - 如何使用 Python 和 Selenium Webdriver 使用 mat-options 查找下拉列表的长度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52339143/

相关文章:

selenium-webdriver - 使用 Selenium webdriver 实现 Metamask 自动化

python - Python中参数的强制命名

python - 在 tkinter 中重新映射默认键绑定(bind)

python - 使用阈值级别 pandas 过滤数据帧

python - 一种使用 Selenium 检查复选框的有效方法

selenium - NoSuchElementException,Selenium 无法定位元素

python - 使用 ffmpeg 和 python 将视频中的所有音频流提取到单独的音频文件中

javascript - 从标签 python 的 onclick 属性获取 URL

ruby 网络驱动程序 : how to access invisible div's text?

python - Selenium-webdriver 计数表数组