What I want
<div class="first second">
<p>get text</p>
</div>
<div class="first second third">
<p>not get text</p>
</div>
For the above class defined html, I want to use selenium’s find_elements css selector to get only the text "get text"
in <p>
of class=“first second”
with the css selector.
Not get text not get text
in <p>
of class=“first second third”
.
Occurring problem
The following code outputs both get text
and not get text
. How can I get only the get text
?
elements = driver.find_elements(By.CSS_SELECTOR, ".first.second :not(.third)")
for element in elements:
print(element.text)
New contributor
昂希柳谷 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.