Got a dynamic table with clickable rows. I am trying to iterate over all rows however I can only click on the first row before receiving the following error:
StaleElementReferenceException: stale element reference: element is not attached to the page document
Workable code below:
# Retrive table and rows
table_id = driver.find_element(By.CLASS_NAME, "ember-table-overflow")
rows = table_id.find_elements(By.TAG_NAME, "tr")
back_btn = driver.find_element(By.CLASS_NAME,"navigation__links")
# Total number of components
print(len(rows))
comp_list = []
for row in rows[1:2]:
print(row)
time.sleep(10)
row.click()
soup = BeautifulSoup(driver.page_source,'lxml')
kind = soup.find_all("div", {"class": "component-view-spec__body"})[0].text
print(kind)
LV = soup.find_all("div", {"class": "component-view-spec__body"})[1].text
comp_data = {
'Kind': kind,
'LV': LV,
}
comp_list.append(comp_data)
back_btn.click()
Code error when iterating more than one row:
# Total number of components
print(len(rows))
comp_list = []
for row in rows[1:3]:
print(row)
time.sleep(10)
row.click()
soup = BeautifulSoup(driver.page_source,'lxml')
kind = soup.find_all("div", {"class": "component-view-spec__body"})[0].text
print(kind)
LV = soup.find_all("div", {"class": "component-view-spec__body"})[1].text
comp_data = {
'Kind': kind,
'LV': LV,
}
comp_list.append(comp_data)
back_btn.click()
Can someone point out why it errors out on row.click() ? Is it a timeout issue?