when I try to get li elements inside a ul I only get one li and nothing else


I’m trying to build a data extract for my company and I need to get the data inside a html list but when I execute my code I only get the text of a single li element below I shared my code.

screenshots of the site source and my result.

My code:

from selenium import webdriver
driver = webdriver.Safari()


results = driver.find_element_by_xpath("//ul[@class='firma-info']/li")

Heres the site and the list data I want to extract

But despite my efforts the result I get is the same I only get the text from first li element like this:



Its because driver.find_element_by_xpath is returning first element. It may highlight to all the li in the DOM, but you are asking to find a single element and it returns the first one.

Use find_elements to find all the li tags and iterate to get the text from them.

results = driver.find_elements_by_xpath("//ul[@class='firma-info']/li")
for result in results:

Answered By – pmadhu

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published