For the first error message:
In short, the message is saying that the element you're looking for is no longer in the DOM, or it changed.
You may be able to try something like below to help
# Add some items to your import statements, to help handle exceptions
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import StaleElementReferenceException
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions
# Then, add some code to help handle exceptions
target_Tag_Name = "p"
ignored_exceptions=(NoSuchElementException,StaleElementReferenceException)
your_element = WebDriverWait(your_driver, some_timeout,ignored_exceptions=ignored_exceptions)\
.until(expected_conditions.presence_of_element_located((By.TAG_NAME, target_Tag_Name)))
# Then place your code below
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")
The link below may offer a bit more context for the first error message:
StaleElementReferenceException on Python Selenium
For the second error message:
In short, the message is saying that the element can't be found on the page.
This could happen because your script is running too quickly, and the page doesn't have time to load fully.
There are a few ways to help address that - the thread below may offer some more context
selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element:
Note that the code snippet above the your_element
variable includes a WebDriverWait
statement, which may slow the execution of your script enough to allow the page to load (Basically the code snippet above might solve the second error message)