BKCapri
BKCapri

Reputation: 558

Python Selenium Click on all li in ul

Hi Ive used the following code and it works perfectly well. How can I make it click all the li items in a ul with an empty ie class="" >With an Xpath of

 Xpath is ('//*[@id="Main_data"]/div[1]ul/li[1]/a/span')

 html_list = driver.find_element_by_id("myId")
 items = html_list.find_elements_by_tag_name("li")
 for item in items:
 text = item.text
 print text

Ive tried item.click in the loop but obtained no results.

Upvotes: 0

Views: 9031

Answers (1)

alecxe
alecxe

Reputation: 473873

To locate elements having an empty class, use the "by XPath" locator:

items = driver.find_elements_by_xpath("//ul[@id = 'myId']//li[not(@class)]")
for item in items:
    item.click()

Upvotes: 2

Related Questions