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, 1635 Views

Hey everyone!

Struggling a bit here—trying to selenium find last li in ul but not getting it right. Tried a few things like `driver.find_elements_by_xpath("//ul/li")[-1]`, but it feels kinda hacky.

Is there a cleaner way? Maybe with CSS selectors or something more reliable?

Also, what if the list updates dynamically? Would love some tips or your go-to methods for this.

Thanks in advance! 🙌

(PS: If you’ve got a snippet, even better—my brain’s fried from trial and error lol.)

Messages In This Thread
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 - by - 15-12-2024, 06:49 AM



Users browsing this thread: 1 Guest(s)