Session Identified by is unknown

I am working on automating testcases for a mobile application in Python and I have recently started facing an issue. Thing were working completely fine earlier but now for some reason the following error pops up. Any idea on how to solve this issue?

selenium.common.exceptions.InvalidSessionIdException: Message: The session identified by 25030467-b3ad-4f74-a6ce-10f8ffab97c3 is not known
Stacktrace:
io.appium.uiautomator2.common.exceptions.NoSuchDriverException: The session identified by 25030467-b3ad-4f74-a6ce-10f8ffab97c3 is not known
at io.appium.uiautomator2.handler.request.SafeRequestHandler.handle(SafeRequestHandler.java:54)
at io.appium.uiautomator2.server.AppiumServlet.handleRequest(AppiumServlet.java:266)
at io.appium.uiautomator2.server.AppiumServlet.handleHttpRequest(AppiumServlet.java:260)
at io.appium.uiautomator2.http.ServerHandler.channelRead(ServerHandler.java:68)
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.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:266)
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:920)

Solution: What you need to do is to uninstall uiautomator apps. Go to Android settings → Apps. Then search for uiautomator, 2 apps will pop up. Uninstall those and you’ll be good to go. This error occurs when the sessions crash over and over again so change your code in such a way that if it causes some error, it automatically quits the driver.

2 Likes

Probably should post the code that produces the error. That would help a lot.

Hi, it happened to me now for the second time.
I am testing both android and ios using mac. As well I am using one appium port.
I quit all the emulators/simulators I had open and any appium server as well.
Then, I relaunched the only simulator I wanted to use and an appium server and all worked fine again.
Hope it helps.

Additionally, I think it is an appium related issue since I saw somewhere in appium logs that it is intentionally switching sessions ids…

As well, maybe it is worth to try upload an issue in appium github repo and see there, or here as well.

Which appium version do you use? I updated lately and it didn’t happen to me before.

@ido_oserovitz @Umer_Saeed
Could you please confirm how the issue got resolved? I’m seeing the same issue now

"Encountered internal error running command: io.appium.uiautomator2.common.exceptions.NoSuchDriverException: The session identified by 368fb888-8cf7-4701-927c-a1b9f2768cd7 is not known "

What you need to do is to uninstall uiautomator apps. Go to Android settings -> Apps. Then search for uiautomator, 2 apps will pop up. Uninstall those and you’ll be good to go. This error occurs when the sessions crash over and over again so change your code in such a way that if it causes some error, it automatically quits the driver.

20 Likes

Thanks @Umer_Saeed, your suggestion solve the issue.

To be specific, I uninstalled these two apps

  1. io.appium.uiautomator2.server
  2. io.appium.uiautomator2.server.test
7 Likes

I use these commands to uninstall in such situations:

adb uninstall io.appium.uiautomator2.server
adb uninstall io.appium.uiautomator2.server.test
adb uninstall io.appium.unlock
adb uninstall io.appium.settings

5 Likes

thanks Umer, really helpful .
it works

2 Likes

Your contribution saved my day. I have troubleshooted for the past 8 hours.

1 Like

How do I permanently uninstall them? I go into the emulator to uninstall and whenever I re-open the emulator they are back on the device.

Once i removed these, Appium was able to launch the Android emulator, but it seems as if I can’t control it. I am unable to print the pageSource, unable to save a screenshot of the device.

1 Like

Thank you @Umer_Saeed. It works to me.

1 Like

hey @Umer_Saeed lately I am working on automation scripts using YAML, R2
While starting session in appium- I am getting this error-
Encountered internal error running command: io.appium.uiautomator2.common.exceptions.NoSuchDriverException: The session identified by 97542aaa-f400-4677-b6f0-f89b0ef8a754 is not known

I can’t find uiautomator in Android settings -> Apps

hi @ammar i’m very new to katalon can you pls say me where do i write these commands

I could not find uiautomator apps in Android settings -> Apps but these commands worked for me Thanks.

1 Like

it worked for me. Thank you very much.

@Umer_Saeed worked thank you

Thank you @Umer_Saeed. It works to me.

I still dont get what causes that problem? how to prevent it? Will it be ever fixed by appium team?

Thank you @Umer_Saeed! This solution helped me and saved the hustle.