Is it possible to get_attribute() from several elements with the same name?
you can use xpath:
listOfLi = driver.find_elements_by_xpath("//li[class='test class']")
or css selector:
listOfLi = driver.find_elements_by_css_selector(".test.class")
you can access each li element by indexing them one by one:
for eachLiElement in listOfLi: string = eachLiElement.get_attribute("id")
string
will give you each element's id.
If you only want to get the second id, you can do it by
secondId = listOfLi[1].get_attribute("id")
secondId
will have 222-22-222
Using get_attribute()
to extract the value of the id attributes of all the <li>
tags you can use the following solution:
print([my_element.get_attribute("id") for my_element in driver.find_elements_by_css_selector('li.test.class')])