I'm trying to run a for loop in a website table with Selenium. I'm using Xpath to get the data.
When I run this solo, I get the proper output:
driver.find_element_by_xpath('//*[@id="top-team-stats-summary-content"]/tr[1]/td[2]').text
But when I put in a for loop to extract all values, it runs an error
vals = (list(np.arange(0,20,1)))
for i in vals :
print(driver.find_element_by_xpath('//*[@id="top-team-stats-summary-content"]/tr[i]/td[2]').text)
Error:
NoSuchElementException: Message: no such element: Unable to locate element:
{"method":"xpath","selector":"//*[@id="top-team-stats-summary-content"]/tr[i]/td[2]"}
This is the HTML
<td class="goal ">59</td>
Any thoughts?
EDIT: Before coming to a post, I looked at this post, that helped me a lot.