【发布时间】:2021-08-26 16:55:37
【问题描述】:
假设我有一个如下所示的 HTML:
<div class="first second">
Right!
</div>
<div class="first second third fourth">
Wrong!
</div>
<div class="first second">
Right!
</div>
如果我尝试使用 css 定位第一个和第三个 div:
driver.find_elements_by_class_name("first, second")
我没有在我的列表中获得 2 个元素,而是获得了所有三个 div,因为第二个 div 实际上包含这些类和其他一些......我该如何限制它,只找到 <div>s :
class = "first second"
【问题讨论】:
-
你有什么标签包含
first, second第三个标签也包含同样的东西。 -
你不能使用 Xpath?
标签: python css selenium class classname