question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

click the same element twice or more, throw a uiautomator exception

See original GitHub issue

@wenshi11019 commented on Thu Dec 01 2016

when I click the same element twice or more, use two of the same click on the statements, or use the for statement, it will throw a exception.

sometimes before i click the element, use Thread.sleep(1000),it can run success, but sometime it still throw the same exception

appium version:1.6.1 appium-uiautomator2-server version: 0.0.6

org.openqa.selenium.StaleElementReferenceException: android.support.test.uiautomator.StaleObjectException at android.support.test.uiautomator.UiObject2.getAccessibilityNodeInfo(UiObject2.java:629) at android.support.test.uiautomator.UiObject2.getVisibleBounds(UiObject2.java:210) at android.support.test.uiautomator.UiObject2.getVisibleCenter(UiObject2.java:251) at android.support.test.uiautomator.UiObject2.click(UiObject2.java:343) at io.appium.uiautomator2.model.UiObject2Element.click(UiObject2Element.java:42) at io.appium.uiautomator2.handler.Click.safeHandle(Click.java:39) at io.appium.uiautomator2.handler.request.SafeRequestHandler.handle(SafeRequestHandler.java:54) at io.appium.uiautomator2.server.AppiumServlet.handleRequest(AppiumServlet.java:201) at io.appium.uiautomator2.server.AppiumServlet.handleHttpRequest(AppiumServlet.java:192) 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.processSelectedKeysPlain(NioEventLoop.java:514) at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:468) 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:818)


@sravanmedarapu commented on Thu Dec 01 2016

Have you tried by setting implicit wait ?


@wenshi11019 commented on Thu Dec 01 2016

@sravanmedarapu it doesn’t work, and thorw the same exception. But use the Thread.sleep() can work.


@sravanmedarapu commented on Thu Dec 01 2016

@wenshi11019 is the element in scrollable view ?


@wenshi11019 commented on Thu Dec 01 2016

@sravanmedarapu yeah, I click the contacts elements twice, or click back button twice.


@sravanmedarapu commented on Thu Dec 01 2016

Unlike Google UiAutomator, UiAutomator2 throws StaleObjectException when the underlying view is changed.

Please refer this: https://github.com/appium/appium-uiautomator2-server/wiki#behavioral-changes-with-respect-to-existing-appium-android-driverbootstrap

However this is something we should look into and find optimal solution.

As a work around, you can try to re find the element when the underlying view is changed.


@wenshi11019 commented on Thu Dec 01 2016

Thanks, I try this way.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:33 (1 by maintainers)

github_iconTop GitHub Comments

10reactions
swat-droidcommented, Sep 20, 2019

No The issue is still there.

7reactions
igalepcommented, Dec 14, 2017

I was trying to avoid the element caching but the suggested solution is the way how we work with PageObjects , the element is the Page’s property which is being initialised on the page’s creation.

By changing it to “driver.findElement” we are breaking the concept …

I was wonder if there a ways to “refresh” the initialised page object ?

so by doing that we are refreshing all the cached elements

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to press a button twice using Google UiAutomator?
getBounds() multiple times on the same object doesn't seem to work. ... void clickByText(String text) throws UiObjectNotFoundException ...
Read more >
A brand new website interface for an even better experience!
click the same element twice or more, throw a uiautomator exception.
Read more >
UIAutomatorViewer Tutorial: Inspect Elements On Android
This Tutorial Explains How to Download, Install & Configure UIAutomator and how to use UIAutomatorViewer to inspect Element on Android ...
Read more >
androidx.compose.ui.test
Asserts that this collection contains at least one element that satisfies the ... Performs a double click gesture (aka a double tap) on...
Read more >
scrollTo (String text) method of Android Driver not working
Yes. i m trying to open contacts App on my android device and want to scroll upto one of the contact name. earlier...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found