1

I'm using selenium webdriver and i need to count all table elements for example:

driver.find_element_by_xpath('//*[@id="mainholder"]/table[4]/tbody/tr[1]/td[1]/form[3]/table[4]')
driver.find_element_by_xpath('//*[@id="mainholder"]/table[4]/tbody/tr[1]/td[1]/form[3]/table[5]')
driver.find_element_by_xpath('//*[@id="mainholder"]/table[4]/tbody/tr[1]/td[1]/form[3]/table[6]')

This will return 3 for my counter but if i have more then these 3 ?

2 Answers 2

1

Use .find_elements_by_xpath():

tables = driver.find_elements_by_xpath('//*[@id="mainholder"]/table[4]/tbody/tr[1]/td[1]/form[3]/table')
print(len(tables))
Sign up to request clarification or add additional context in comments.

Comments

0

Have you tried

mytables = driver.find_elements_by_css_selector("table")

This might do the job.

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.