<p>该网站是<a href="https://www.webstaurantstore.com/25887/commercial-gas-ranges.html?page=1" rel="nofollow noreferrer">https://www.webstaurantstore.com/25887/commercial-gas-ranges.html?page=1</a>。当我想定位右上角的搜索字段并在那里发送then键时,它就起作用了。但是,当我想在执行一次搜索后执行相同的操作时,它不起作用。selenium可以定位元素,但不能向其发送密钥。为什么会发生这样的事情?我怎样才能避免呢</p>
<pre><code>while True:
try:
a = self.webdriver.find_element_by_xpath('/html/body/div[3]/div[1]/div[2]/div[2]/div/div[2]/div/form/div/input')
except:
pass
else:
a.send_keys(i.text[1:])
break
</code></pre>
<p>错误:</p>
<pre><code>>>>selenium.common.exceptions.StaleElementReferenceException: Message: stale element reference: element is not attached to the page document
(Session info: chrome=81.0.4044.138)
</code></pre>