I have been trying to run the following code in three different weblinks. Code works fine on one weblink. However, it throws an error message about "Message: stale element reference: element is not attached to the page document". I looked into forum's two previous threads (Python Selenium stale element fix and How to Navigate to a New Webpage In Selenium?) about the same error message but didn't get sort it out the issue.
Here is my code:
driver.get('https://github.com/avassalotti')
contributions = driver.find_elements_by_xpath(".//ul[@class='filter-list small']//li")
print(contributions)
for item in contributions:
print (item)
print(item.text)
item.click()
time.sleep(3)
contribution = driver.find_element_by_xpath(".//*[@class='f4 text-normal mb-2']").text
print(contribution)
Program works for this link (https://github.com/alex) and does not work for (https://github.com/agronholm, https://github.com/avassalotti).
Any advice to fix the issue.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…