Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to loop through only li elements inside a ul

Xpath of ul element:

resultSet = driver.find_element_by_xpath("//section[@id='abc']/ul")

How to loop through only li elements inside a ul, given above ul element xpath?

like image 349
Anshika Jain Avatar asked Nov 22 '17 13:11

Anshika Jain


1 Answers

You can search for li nodes starting from already defined ul with below code:

resultSet = driver.find_element_by_xpath("//section[@id='abc']/ul")
options = resultSet.find_elements_by_tag_name("li")

To loop through list of li nodes simply do

for option in options:
    print(option.text)
like image 147
Andersson Avatar answered Oct 02 '22 17:10

Andersson