How can i reach all li in ul

Viewed 47

How can i reach all li with for loop in python. You can see the codes below :

<ul class="example">
  <li class="example-li"></li>
  <li class="example-li"></li>
  <li class="example-li"></li>
</ul>
 results = self.driver.find_elements_by_xpath(
            "//ul[@class='example']"
        )

 for result in results:
          hover = ActionChains(self.driver).move_to_element(result)
          hover.perform()

 print(len(results)) # expected to print '3'
1 Answers

Your XPath returns all ul nodes, not li. You need to update XPath as

"//ul[@class='example']/li"
Related