Selenium package - StaleElementReferenceException

Hi,
I’ve this part code in my script

elements = driver.find_elements(By.TAG_NAME, 'p')
for e in elements:
    if e.text not in elenco:
        print(e.text)
        elenco.append(e.text)
        if ("Denis" in e.text):                   
                print("Find Denis")

Many times the script break in this rows with this message
selenium.common.exceptions.StaleElementReferenceException: Message: stale element reference: element is not attached to the page document

other times in the other rows (follow) with similar message like:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {“method”:“css selector”,“selector”:“[id=“submitmessage”]”}

It seams like that it find a problem when the webpage change within these rows.
Can someone please help me to fix it?
Thanks

The forum is meant for python, the stdlib, and their docs. If you don’t get an answer here soon, try stackoverflow.com or a selenium forum/list.