I want to use the selenium module for python 3 to get some information from a website, that information is located in a class with the name "table_dark_green". Now the problem is that there are multiple elements on this site with the class name "table_dark_green", and selenium only stores the last element with that class name. Is there a way to specify which one i would like to use?
-
if you ll use xpath then you can specify number of class in square brackets like '//div[@class="table_dark_green"][2]'Robert– Robert2019-02-18 16:56:09 +00:00Commented Feb 18, 2019 at 16:56
-
thank you for your help!Seppukki– Seppukki2019-02-18 17:03:46 +00:00Commented Feb 18, 2019 at 17:03
Add a comment
|
1 Answer
You can use find_elements then specify the element:
# this returns a list of elements
table_elements = driver.find_elements_by_class_name("table_dark_green")
print(len(table_elements)) # print to see how meny elements are in he list
# you can specify the element in the list[0] or [1] ... [99]
print(table_elements[0].text)
Hope this helps you!