Ans*_*ain 7 selenium python-3.x
ul 元素的 Xpath:
resultSet = driver.find_element_by_xpath("//section[@id='abc']/ul")
Run Code Online (Sandbox Code Playgroud)
如何仅遍历 ul 中的 li 元素,在 ul 元素 xpath 上方给出?
您可以使用以下代码li从已定义的节点开始搜索ul:
resultSet = driver.find_element_by_xpath("//section[@id='abc']/ul")
options = resultSet.find_elements_by_tag_name("li")
Run Code Online (Sandbox Code Playgroud)
要遍历li节点列表,只需执行
for option in options:
print(option.text)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5995 次 |
| 最近记录: |