0

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?

2
  • if you ll use xpath then you can specify number of class in square brackets like '//div[@class="table_dark_green"][2]' Commented Feb 18, 2019 at 16:56
  • thank you for your help! Commented Feb 18, 2019 at 17:03

1 Answer 1

1

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!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.