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

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -