@
@
@nixbox2020-08-11 08:28:24
Python
@nixbox, 2020-08-11 08:28:24

How to get child elements excluding their nested elements in Selenium?

Good afternoon.
Code example:

<ul class="comment-list">
<li>First</li>

<li>First
<ul>
<li>SECOND</li
</ul>
</li>

<li>First</li>
<li>First</li>
</ul>

With my code, I get absolutely all nested li
comments_list_parent = driver.find_element_by_css_selector("ul.comment-list")
comments_list = comments_list_parent.find_elements_by_tag_name("li")


How can you get only the li in the comment-list (First) excluding the li inside the first (Second)?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2020-08-11
_

find_elements_by_xpath

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question