appium-uiautomator2-server
appium-uiautomator2-server copied to clipboard
Elements cached error do not exist in dom any more occured by io.appium.uiautomator2.model.ElementsCache.get()
Element which xpath is //android.view.View[@scrollable='true'] is found when calling the appium api driver.findElementsByXapth(), but found element's location cannot be got by getLocation() api.
I want to get the reason about uiautomator2 cache error. Is there any process about uiautomator2 cache such as calling some android api? Besides that, in which case, cached element cannot be used once more?
[appium Log] 2022-07-19 14:59:19:477 [HTTP] --> POST /wd/hub/session/d015dd4b-af9f-4099-8152-45dca49fc451/elements 2022-07-19 14:59:19:477 [HTTP] {"using":"xpath","value":"//android.view.View[@scrollable='true']"} 2022-07-19 14:59:19:477 [W3C (d015dd4b)] Calling AppiumDriver.findElements() with args: ["xpath","//android.view.View[@scrollable='true']","d015dd4b-af9f-4099-8152-45dca49fc451"] 2022-07-19 14:59:19:477 [BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, css selector, -android uiautomator 2022-07-19 14:59:19:477 [BaseDriver] Waiting up to 10000 ms for condition 2022-07-19 14:59:19:478 [WD Proxy] Matched '/elements' to command name 'findElements' 2022-07-19 14:59:19:478 [WD Proxy] Proxying [POST /elements] to [POST http://127.0.0.1:8267/wd/hub/session/e3b368f6-db7b-4071-b2d8-1dfc32978184/elements] with body: {"strategy":"xpath","selector":"//android.view.View[@scrollable='true']","context":"","multiple":true} 2022-07-19 14:59:19:653 [WD Proxy] Got response with status 200: {"sessionId":"e3b368f6-db7b-4071-b2d8-1dfc32978184","value":[{"ELEMENT":"6fbb93e5-e32d-45e7-b397-7b48bd156c19","element-6066-11e4-a52e-4f735466cecf":"6fbb93e5-e32d-45e7-b397-7b48bd156c19"}]} 2022-07-19 14:59:19:654 [W3C (d015dd4b)] Responding to client with driver.findElements() result: [{"element-6066-11e4-a52e-4f735466cecf":"6fbb93e5-e32d-45e7-b397-7b48bd156c19","ELEMENT":"6fbb93e5-e32d-45e7-b397-7b48bd156c19"}] 2022-07-19 14:59:19:656 [HTTP] <-- POST /wd/hub/session/d015dd4b-af9f-4099-8152-45dca49fc451/elements 200 178 ms - 139 2022-07-19 14:59:19:657 [HTTP] 2022-07-19 14:59:19:661 [HTTP] --> GET /wd/hub/session/d015dd4b-af9f-4099-8152-45dca49fc451/element/6fbb93e5-e32d-45e7-b397-7b48bd156c19/location 2022-07-19 14:59:19:661 [HTTP] {} 2022-07-19 14:59:19:662 [W3C (d015dd4b)] Driver proxy active, passing request on via HTTP proxy 2022-07-19 14:59:19:668 [WD Proxy] Matched '/wd/hub/session/d015dd4b-af9f-4099-8152-45dca49fc451/element/6fbb93e5-e32d-45e7-b397-7b48bd156c19/location' to command name 'getLocation' 2022-07-19 14:59:19:669 [WD Proxy] Proxying [GET /wd/hub/session/d015dd4b-af9f-4099-8152-45dca49fc451/element/6fbb93e5-e32d-45e7-b397-7b48bd156c19/location] to [GET http://127.0.0.1:8267/wd/hub/session/e3b368f6-db7b-4071-b2d8-1dfc32978184/element/6fbb93e5-e32d-45e7-b397-7b48bd156c19/location] with no body 2022-07-19 14:59:19:697 [WD Proxy] Got response with status 404: {"sessionId":"e3b368f6-db7b-4071-b2d8-1dfc32978184","value":{"error":"stale element reference","message":"Cached elements 'By.xpath: //android.view.View[@scrollable='true']' do not exist in DOM anymore","stacktrace":"io.appium.uiautomator2.common.exceptions.StaleElementReferenceException: Cached elements 'By.xpath: //android.view.View[@scrollable='true']' do not exist in DOM anymore\n\tat io.appium.uiautomator2.model.ElementsCache.restore(ElementsCache.java:72)\n\tat io.appium.uiautomator2.model.ElementsCache.get(ElementsCache.java:145)\n\tat io.appium.uiautomator2.handler.Location.safeHandle(Location.java:23)\n\tat io.appium.uiautomator2.handler.request.SafeRequestHandler.handle(SafeRequestHandler.java:41)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleRequest(AppiumServlet.java:261)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleHttpRequest(AppiumServlet.java:255)\n\tat io.appium.uiautomator2.http.ServerHandler.channelRead(ServerHandler.java:68)\n\tat io.netty.channel.AbstractChannelHan... 2022-07-19 14:59:19:701 [W3C] Matched W3C error code 'stale element reference' to StaleElementReferenceError 2022-07-19 14:59:19:704 [HTTP] <-- GET /wd/hub/session/d015dd4b-af9f-4099-8152-45dca49fc451/element/6fbb93e5-e32d-45e7-b397-7b48bd156c19/location 404 42 ms - 3977 2022-07-19 14:59:19:704 [HTTP]
This means that the element you found no longer exists (as the same element reference) when you query its location. It may be an element which is constantly being regenerated or reattached in the app source code or something. You could try to find a different element, find the element in a different way, or get the location more quickly (potentially by batching commands using executeDriverScript if you're in a high latency situation).