Reputation: 83
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 ?
Upvotes: 1
Views: 218
Reputation: 41
Have you tried
mytables = driver.find_elements_by_css_selector("table")
This might do the job.
Upvotes: 0
Reputation: 473863
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))
Upvotes: 1