Selenium Python StaleElementReferenceException
<p>I'm trying to download all the pdf on a webpage using Selenium Python with Chrome as browser but every time the session ends with this message:</p>

<pre><code>StaleElementReferenceException: stale element reference: element is not attached to the page document
  (Session info: chrome=52.0.2743.116)
  (Driver info: chromedriver=2.22.397933
</code></pre>

<p>This is the code:</p>

<pre><code>def download_pdf(self):
    current = self.driver.current_url        
    lista_link_temp = self.driver.find_elements_by_xpath("//*[@href]")
    for link in lista_link_temp:
        if "pdf+html" in str(link.get_attribute("href")):
            tutor = link.get_attribute("href")
            self.driver.get(str(tutor))
            self.driver.get(current)
</code></pre>

<p>Please help me.. I've just tried lambda, implicit and explicit wait </p>

<p>Thanks</p>

<p>You get stale element when you search for an element and before doing any action on it the page has changed/reloaded.</p>

<p>Make sure the page is fully loaded before doing any actions in the page.</p>

<p>So you need to add first a condition to wait for the page to be loaded an maybe check all requests are done.</p>

python google-chrome selenium