0

I'm testing an Android App and sometimes I can fill a field and sometimes not

This is the error: InvalidElementStateException: Message: Cannot set the element to '1'. Did you interact with the correct element?

Actually I'm using Input Text and xPath

InvalidElementStateException: Message: Cannot set the element to '1'. Did you interact with the correct element?
Stacktrace:
io.appium.uiautomator2.common.exceptions.InvalidElementStateException: Cannot set the element to '1'. Did you interact with the correct element?
        at io.appium.uiautomator2.handler.SendKeysToElement.setText(SendKeysToElement.java:87)
        at io.appium.uiautomator2.handler.SendKeysToElement.safeHandle(SendKeysToElement.java:115)
        at io.appium.uiautomator2.handler.request.SafeRequestHandler.handle(SafeRequestHandler.java:59)
        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(Abstra...
    [ Message content over the limit has been removed. ]
        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:1012)

I'm expecting the code will work everytime

Ajeet Verma
  • 2,938
  • 3
  • 13
  • 24

1 Answers1

0

I think it is related to finding element by Xpath, on appium there is a similar question solved: Appium question

The solution is to click inside element and print text through an Action instead of using element's properties.

Mircea Sirghi
  • 310
  • 1
  • 6
  • Thank you, I will check that answer, but isnt strange what one time works and next not ? Same field, same code, just different runs – BarnabasTharmr Aug 24 '23 at 13:21
  • It definitely is, I would rather user explicit waits: WebDriverWait wait = new WebDriverWait(driver, 10); wait.until(ExpectedConditions.presenceOfElementLocated(loginBtn)).click();, you can turn it into a smart wait so that it checks for a couple of times. Also you can find it using two different location strategies and use the first that works. – Mircea Sirghi Aug 24 '23 at 14:07