StaleElementException

Hi Guys,

Am getting this issue,

OpenQA.Selenium.StaleElementReferenceException : io.appium.uiautomator2.common.exceptions.StaleElementReferenceException: The element ‘By.xpath: //android.widget.TextView[@text = ‘Get started’]’ does not exist in DOM anymore
at io.appium.uiautomator2.model.KnownElements.getElementFromCache(KnownElements.java:88)
at io.appium.uiautomator2.handler.Click.safeHandle(Click.java:35)
at io.appium.uiautomator2.handler.request.SafeRequestHandler.handle(SafeRequestHandler.java:37)
at io.appium.uiautomator2.server.AppiumServlet.handleRequest(AppiumServlet.java:252)
at io.appium.uiautomator2.server.AppiumServlet.handleHttpRequest(AppiumServlet.java:243)
at io.appium.uiautomator2.http.ServerHandler.channelRead(ServerHandler.java:44)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)
at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)
at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:435)
at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:293)
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:267)
at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:250)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1294)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:911)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:131)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:611)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:552)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:466)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:438)
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:140)
at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:144)
at java.lang.Thread.run(Thread.java:764)

Kindly find the logs below

[HTTP] {}

[MJSONWP (7792fa4c)] Calling AppiumDriver.click() with args: [“fe8c9a74-1fa0-4e65-b54b-f72f7635e959”,“7792fa4c-f54b-44b3-af2e-9020de07b5cb”]

[WD Proxy] Matched ‘/element/fe8c9a74-1fa0-4e65-b54b-f72f7635e959/click’ to command name ‘click’

[WD Proxy] Proxying [POST /element/fe8c9a74-1fa0-4e65-b54b-f72f7635e959/click] to [POST http://localhost:8200/wd/hub/session/52e62138-ea13-4239-ba7a-d8c7e700de24/element/fe8c9a74-1fa0-4e65-b54b-f72f7635e959/click] with body: {“element”:“fe8c9a74-1fa0-4e65-b54b-f72f7635e959”}

[WD Proxy] Got response with status 200: {“sessionId”:“52e62138-ea13-4239-ba7a-d8c7e700de24”,“status”:0,“value”:true}

[MJSONWP (7792fa4c)] Responding to client with driver.click() result: true

[HTTP] <-- POST /wd/hub/session/7792fa4c-f54b-44b3-af2e-9020de07b5cb/element/fe8c9a74-1fa0-4e65-b54b-f72f7635e959/click 200 150 ms - 76

[HTTP]

[HTTP] --> POST /wd/hub/session/7792fa4c-f54b-44b3-af2e-9020de07b5cb/element

[HTTP] {“using”:“xpath”,“value”:"//android.widget.TextView[@text = ‘Get started’]"}

[MJSONWP (7792fa4c)] Calling AppiumDriver.findElement() with args: [“xpath”,"//android.widget.TextView[@text = ‘Get started’]",“7792fa4c-f54b-44b3-af2e-9020de07b5cb”]

[BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator

[BaseDriver] Waiting up to 60000 ms for condition

[WD Proxy] Matched ‘/element’ to command name ‘findElement’

[WD Proxy] Proxying [POST /element] to [POST http://localhost:8200/wd/hub/session/52e62138-ea13-4239-ba7a-d8c7e700de24/element] with body: {“strategy”:“xpath”,“selector”:"//android.widget.TextView[@text = ‘Get started’]",“context”:"",“multiple”:false}

[WD Proxy] Got response with status 200: {“sessionId”:“52e62138-ea13-4239-ba7a-d8c7e700de24”,“status”:0,“value”:{“ELEMENT”:“5318c997-0660-404d-a979-c471727250e2”}}

[MJSONWP (7792fa4c)] Responding to client with driver.findElement() result: {“element-6066-11e4-a52e-4f735466cecf”:“5318c997-0660-404d-a979-c471727250e2”,“ELEMENT”:“5318c997-0660-404d-a979-c471727250e2”}

[HTTP] <-- POST /wd/hub/session/7792fa4c-f54b-44b3-af2e-9020de07b5cb/element 200 705 ms - 199

[HTTP]

[HTTP] --> POST /wd/hub/session/7792fa4c-f54b-44b3-af2e-9020de07b5cb/element/5318c997-0660-404d-a979-c471727250e2/click

[HTTP] {}

[MJSONWP (7792fa4c)] Calling AppiumDriver.click() with args: [“5318c997-0660-404d-a979-c471727250e2”,“7792fa4c-f54b-44b3-af2e-9020de07b5cb”]

[WD Proxy] Matched ‘/element/5318c997-0660-404d-a979-c471727250e2/click’ to command name ‘click’

[WD Proxy] Proxying [POST /element/5318c997-0660-404d-a979-c471727250e2/click] to [POST http://localhost:8200/wd/hub/session/52e62138-ea13-4239-ba7a-d8c7e700de24/element/5318c997-0660-404d-a979-c471727250e2/click] with body: {“element”:“5318c997-0660-404d-a979-c471727250e2”}

[WD Proxy] Got an unexpected response: {“sessionId”:“52e62138-ea13-4239-ba7a-d8c7e700de24”,“status”:10,“value”:"io.appium.uiautomator2.common.exceptions.StaleElementReferenceException: The element ‘By.xpath: //android.widget.TextView[@text = ‘Get started’]’ does not exist in DOM anymore\n\tat io.appium.uiautomator2.model.KnownElements…

[MJSONWP] Matched JSONWP error code 10 to StaleElementReferenceError

[MJSONWP (7792fa4c)] Encountered internal error running command: StaleElementReferenceError: io.appium.uiautomator2.common.exceptions.StaleElementReferenceException: The element ‘By.xpath: //android.widget.TextView[@text = ‘Get started’]’ does not exist in DOM anymore

[MJSONWP (7792fa4c)] at io.appium.uiautomator2.model.KnownElements.getElementFromCache(KnownElements.java:88)

[MJSONWP (7792fa4c)] at io.appium.uiautomator2.handler.Click.safeHandle(Click.java:35)

[MJSONWP (7792fa4c)] at io.appium.uiautomator2.handler.request.SafeRequestHandler.handle(SafeRequestHandler.java:37)

[MJSONWP (7792fa4c)] at io.appium.uiautomator2.server.AppiumServlet.handleRequest(AppiumServlet.java:252)

[MJSONWP (7792fa4c)] at io.appium.uiautomator2.server.AppiumServlet.handleHttpRequest(AppiumServlet.java:243)

[MJSONWP (7792fa4c)] at io.appium.uiautomator2.http.ServerHandler.channelRead(ServerHandler.java:44)

[MJSONWP (7792fa4c)] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)

[MJSONWP (7792fa4c)] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)

[MJSONWP (7792fa4c)] at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)

[MJSONWP (7792fa4c)] at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102)

[MJSONWP (7792fa4c)] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)

[MJSONWP (7792fa4c)] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)

[MJSONWP (7792fa4c)] at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)

[MJSONWP (7792fa4c)] at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:435)

[MJSONWP (7792fa4c)] at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:293)

[MJSONWP (7792fa4c)] at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:267)

[MJSONWP (7792fa4c)] at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:250)

[MJSONWP (7792fa4c)] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)

[MJSONWP (7792fa4c)] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)

[MJSONWP (7792fa4c)] at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)

[MJSONWP (7792fa4c)] at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1294)

[MJSONWP (7792fa4c)] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)

[MJSONWP (7792fa4c)] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)

[MJSONWP (7792fa4c)] at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:911)

[MJSONWP (7792fa4c)] at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:131)

[MJSONWP (7792fa4c)] at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:611)

[MJSONWP (7792fa4c)] at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:552)

[MJSONWP (7792fa4c)] at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:466)

[MJSONWP (7792fa4c)] at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:438)

[MJSONWP (7792fa4c)] at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:140)

[MJSONWP (7792fa4c)] at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:144)

[MJSONWP (7792fa4c)] at java.lang.Thread.run(Thread.java:764)

[MJSONWP (7792fa4c)]

[MJSONWP (7792fa4c)] at errorFromMJSONWPStatusCode (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-base-driver/lib/protocol/errors.js:786:12)

[MJSONWP (7792fa4c)] at ProxyRequestError.errorFromMJSONWPStatusCode [as getActualError] (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-base-driver/lib/protocol/errors.js:683:14)

[MJSONWP (7792fa4c)] at JWProxy.getActualError [as command] (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-base-driver/lib/jsonwp-proxy/proxy.js:234:19)

[HTTP] <-- POST /wd/hub/session/7792fa4c-f54b-44b3-af2e-9020de07b5cb/element/5318c997-0660-404d-a979-c471727250e2/click 500 1859 ms - 3413

[HTTP]

[HTTP] --> DELETE /wd/hub/session/7792fa4c-f54b-44b3-af2e-9020de07b5cb

[HTTP] {}

[MJSONWP (7792fa4c)] Calling AppiumDriver.deleteSession() with args: [“7792fa4c-f54b-44b3-af2e-9020de07b5cb”]

[BaseDriver] Event ‘quitSessionRequested’ logged at 1558231420553 (03:03:40 GMT+0100 (BST))

[Appium] Removing session 7792fa4c-f54b-44b3-af2e-9020de07b5cb from our master session list

[UiAutomator2] Deleting UiAutomator2 session

[UiAutomator2] Deleting UiAutomator2 server session

[WD Proxy] Matched ‘/’ to command name ‘deleteSession’

[WD Proxy] Proxying [DELETE /] to [DELETE http://localhost:8200/wd/hub/session/52e62138-ea13-4239-ba7a-d8c7e700de24] with no body

[WD Proxy] Got response with status 200: “{“sessionId”:“52e62138-ea13-4239-ba7a-d8c7e700de24”,“status”:0,“value”:“Session deleted”}”

[ADB] Running ‘/Users/jebran/Library/Android/sdk/platform-tools/adb -P 5037 -s LGM70023758447 shell am force-stop uk.co.vanquis.app’

[Instrumentation] .

[Logcat] Stopping logcat capture

[ADB] Removing forwarded port socket connection: 8200

[ADB] Running ‘/Users/jebran/Library/Android/sdk/platform-tools/adb -P 5037 -s LGM70023758447 forward --remove tcp:8200’

[BaseDriver] Event ‘quitSessionFinished’ logged at 1558231420858 (03:03:40 GMT+0100 (BST))

[MJSONWP (7792fa4c)] Received response: null

[MJSONWP (7792fa4c)] But deleting session, so not returning

[MJSONWP (7792fa4c)] Responding to client with driver.deleteSession() result: null

[HTTP] <-- DELETE /wd/hub/session/7792fa4c-f54b-44b3-af2e-9020de07b5cb 200 307 ms - 76

[HTTP]

[Instrumentation] Time: 27.114

[Instrumentation]

[Instrumentation] OK (1 test)

[Instrumentation] The process has exited with code 0

can i see part of coding?

Hi Please,
Close the bug,
Its fixed,

can you please post the solution @sheikh_jebran

i’m facing the same issue, please post the solution

The guys , apology for delay in reply, i moved the Driver object to global class rather than passing as scenarioContext object, and hence solved the issue