# The element identified by id either not present or it has expired from the internal cache

**URL:** <https://discuss.appium.io/t/the-element-identified-by-id-either-not-present-or-it-has-expired-from-the-internal-cache/33051>\
**Category:** Issues/Bugs\
**Created:** [February 17, 2021, 5:39am UTC](https://discuss.appium.io/t/the-element-identified-by-id-either-not-present-or-it-has-expired-from-the-internal-cache/33051 "2021-02-17T05:39:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lien\_Khuong](https://discuss.appium.io/user_avatar/discuss.appium.io/lien_khuong/32/8241_2.png) [@Lien\_Khuong](https://discuss.appium.io/u/Lien_Khuong)\
**Post date:** [February 17, 2021, 5:39am UTC](https://discuss.appium.io/t/the-element-identified-by-id-either-not-present-or-it-has-expired-from-the-internal-cache/33051/1 "2021-02-17T05:39:01Z")

</div>

Hello  
I am facing the issue

> Blockquote  
> org.openqa.selenium.StaleElementReferenceException: The element identified by “9BEA0100-0000-0000-5C01-000000000000” is either not present or it has expired from the internal cache. Try to find it again  
> For documentation on this error, please visit: [/documentation/webdriver/troubleshooting/errors/](https://www.seleniumhq.org/exceptions/stale_element_reference.html)  
> Build info: version: ‘3.141.59’, revision: ‘e82be7d358’, time: ‘2018-11-14T08:17:03’  
> ession ID: c0c92aa0-d7f5-4c37-86ef-e17e301c5343  
> at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)  
> at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)  
> at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)  
> at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)  
> at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)  
> at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)  
> at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)  
> at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)  
> at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)  
> at io.appium.java\_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:239)  
> at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)  
> at io.appium.java\_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:41)  
> at io.appium.java\_client.AppiumDriver.execute(AppiumDriver.java:1)  
> at io.appium.java\_client.ios.IOSDriver.execute(IOSDriver.java:1)  
> at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:285)  
> at io.appium.java\_client.DefaultGenericMobileElement.execute(DefaultGenericMobileElement.java:45)  
> at io.appium.java\_client.MobileElement.execute(MobileElement.java:1)  
> at io.appium.java\_client.ios.IOSElement.execute(IOSElement.java:1)  
> at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:84)

Appium version: 1.20.1  
Ipad iOS: 14.1

The test case is running within 2-3 hours and then the exception is thrown  
Have you ever to meet this issue ? Please help

---

<div class="post-metadata">

**Author:** ![kitoymonster](https://discuss.appium.io/user_avatar/discuss.appium.io/kitoymonster/32/8465_2.png) [@kitoymonster](https://discuss.appium.io/u/kitoymonster)\
**Post date:** [February 17, 2021, 8:35am UTC](https://discuss.appium.io/t/the-element-identified-by-id-either-not-present-or-it-has-expired-from-the-internal-cache/33051/2 "2021-02-17T08:35:26Z")

</div>

You might have fetched the element before and then it was changed but you are still using the previous state of the element.

You can fix this adding a try-catch for StaleElementReferenceException then do a re-fetching until the element is visible.

```
async function waitForLocated (driver: WebDriverClass, locator: WebDriverLocator, retries?: number = 3)
   try {
     await driver.wait(until.elementLocated(locator), 7000)
   } catch (err) {
     if (retries === 0) {
      throw new Error(`Still not able to locate element ${locator.toString()} after maximum retries, Error message: ${err.message.toString()}`)
     }
    await driver.sleep(250)
     return waitForLocated(driver, locator, retries - 1)
   }
 }
```
