How to iterate a unordered list in Python Selenium -
i iterate through below elements in python using selenium webdriver.
<ul class="skills-section"> <li class="endorse-item has-endorsements " data-endorsed-item-name="ear surgery"> <li class="endorse-item has-endorsements " data-endorsed-item-name="healthcare"> <li class="endorse-item has-endorsements " data-endorsed-item-name="hospitals"> <li class="endorse-item has-endorsements " data-endorsed-item-name="surgery"> <li class="endorse-item has-endorsements " data-endorsed-item-name="medical education"> <li class="endorse-item has-endorsements " data-endorsed-item-name="pediatrics"> <li class="endorse-item has-endorsements " data-endorsed-item-name="treatment"> <li class="endorse-item has-endorsements " data-endorsed-item-name="public health"> <li class="endorse-item has-endorsements " data-endorsed-item-name="patient safety"> <li class="endorse-item has-endorsements " data-endorsed-item-name="emergency medicine"> </ul>
what tried?
skillssection = a.find_element_by_xpath("//ul[contains(@class, 'skills-section')]") skillslist = skillssection.find_elements_by_tag_name("li") skill in skillslist: print skill.find_element_by_xpath("//span[contains(@class,endorse-item-name')]/a").text
but problem is, printing first element value. element not incrementing.
what you'll want find tag 'ul'
class='skills-section'
, iterate on children.
skillssection = a.find_element_by_xpath("//ul[contains(@class, 'skills-section')]") child in skillssection.find_elements_by_xpath(".//*"): ...
see answer more details: selenium python children elements
Comments
Post a Comment