gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 09:02:45 25 4
gpt4 key购买 nike

我正在处理使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com