首页 > 解决方案 > 如何找到子元素

问题描述

如何找到子元素。在下面我需要在 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()

标签: pythonseleniumselenium-webdriverxpathselenium-chromedriver

解决方案


我认为您的问题是您正在寻找elements并且您只希望返回一个元素。在查找元素时,它会返回一个列表。

试试这个。

find = driver.find_element_by_css_selector(".parent a")
find.click()


推荐阅读