Selenium: stale element reference: element is not attached to the page document in Python
<p>I'm using Python's version of Selenium to iterate through Select elements options. It works quite well on of the websites, but fails on the another one, with error: <code>Message: stale element reference: element is not attached to the page document</code> I looked it up of course, but the answers I found didn't work out for me. I use <code>time.sleep()</code> to wait for page to load and I can see it being loaded in the browser. I'm not sure what should I do with it.</p>

<p>How it looks in code:</p>

<pre><code>options = Select(driver.find_element_by_xpath("my_element's_xpath")).options
for option in options:
    option.click()
    sleep(5)
</code></pre>

<p>First run it works fine, second run I get the error. </p>

<p>Here is the Select element in Dev Tools in Chromium:
<a href="https://i.stack.imgur.com/uX7g7.png" rel="nofollow noreferrer">screenshot</a>
I believe it might have to do something with first select option not having <code>&lt;option&gt;</code> tag around it, but I'm not sure how to remove it from DOM.</p>