How to use Selenium to find the last li in ul? or What's the best way to find the last li in ul using

16 Replies, 1470 Views

Honestly, your XPath hack isn’t *that* bad. But yeah, `:last-child` is cleaner.

If the list’s super dynamic, maybe even check for `li` count first with `len(driver.find_elements_by_css_selector("ul li"))` to be safe.

Messages In This Thread



Users browsing this thread: 1 Guest(s)