Tag Archives: staleelementreferenceexception exception

[Solved] Selenium error: staleelementreferenceexception exception

StaleElementReferenceException

Problem reporting and solution

Problem reporting error

# clcik to the next page
web.find_element_by_xpath('//*[@id="nexthehe"]').click()

the element is no longer attached to the DOM : the element is no longer attached to the dom

Solution:

The element is no longer attached to the dom

Analyze the cause

It is possible that elements that are no longer attached to the DOM tree are guided (for example, document. Documentelement)

But the page content is not loaded and cannot be found

resolvent:

Still, looking for the element again

try:
    # clcik to the next page
    web.find_element_by_xpath('//*[@id="nexthehe"]').click()
    # time.sleep(1)
except Exception:
    print('failed to next page')
    web.find_element_by_xpath('//*[@id="nexthehe"]').click()