python - 如何找到子元素
问题描述
如何找到子元素。在下面我需要在 P Tag 中选择 A 标签。错误对象没有可单击的属性。
<p class="parent">
Stack
<a href="https://stackoverflow.com">overflow</a>
</p>
Python代码
find = driver.find_elements_by_css_selector("p.parent>a")
find.click()
解决方案
我认为您的问题是您正在寻找elements
并且您只希望返回一个元素。在查找元素时,它会返回一个列表。
试试这个。
find = driver.find_element_by_css_selector(".parent a")
find.click()
推荐阅读
- kendo-ui - 剑道网格功能'selectedKeyNames'没有检索多行
- vb.net - 如何在 vb.net 中更改全局变量时引发事件
- sql-server - 如何在不重复子句的情况下分配多个变量
- sequelize.js - 如何使用feather-sequelize在featherjs的连接表中设置belongsToMany关系和附加属性
- python - 我如何知道输入数据到我的 keras RNN 的正确格式?
- javascript - 在 React JS 中渲染图像的问题
- vba - 检查子表单中的记录集时引用无效
- python - Airflow Dag 不会因 python 脚本失败而失败
- arrays - 为什么在使用 ReadBytesExt 从字节片中读取整数时出现错误“特征界限不满足”?
- powershell - 如何更改 dir cmd 列出的文件的顺序