51Testing软件测试论坛

标题: Appium 的 UIAutomator2 模式下使用 sendKeys 出现错误。 [打印本页]

作者: 测试积点老人    时间: 2019-8-26 13:54
标题: Appium 的 UIAutomator2 模式下使用 sendKeys 出现错误。
问题描述
使用Appium做UI自动化测试,因为要获取到Toast信息,就用了UIAutomator2模式。登录App后,有一个设置6个密码的步骤。如下图
[attach]126291[/attach]
上面有阴影的地方就是用来输入密码。布局如下图:
[attach]126292[/attach]
我一开始的做法是想直接获取到“android.widget.LinearLayout” 然后输入6个数字的字符串。Appium能定位到元素的位置,但使用sendKey时候报了如下的错误:
  1. [JSONWP Proxy] Got an unexpected response: {"sessionId":"6098f2ff-17b6-4843-95d6-18b84cbccdfe","status":12,"value":"io.appium.uiautomator2.common.exceptions.InvalidElementStateException: Cannot set the element to '666666'. Did you interact with the correct element?\n\tat io.appium.uiautomator2.handler.SendKeysToElement.safeHandle(SendKeys...
  2. [MJSONWP] Matched JSONWP error code 12 to InvalidElementStateError
  3. [MJSONWP (c790c823)] Encountered internal error running command: InvalidElementStateError: io.appium.uiautomator2.common.exceptions.InvalidElementStateException: Cannot set the element to '666666'. Did you interact with the correct element?
  4. [MJSONWP (c790c823)] at io.appium.uiautomator2.handler.SendKeysToElement.safeHandle(SendKeysToElement.java:96)
  5. [MJSONWP (c790c823)] at io.appium.uiautomator2.handler.request.SafeRequestHandler.handle(SafeRequestHandler.java:37)
  6. [MJSONWP (c790c823)] at io.appium.uiautomator2.server.AppiumServlet.handleRequest(AppiumServlet.java:250)
  7. [MJSONWP (c790c823)] at io.appium.uiautomator2.server.AppiumServlet.handleHttpRequest(AppiumServlet.java:241)
  8. [MJSONWP (c790c823)] at io.appium.uiautomator2.http.ServerHandler.channelRead(ServerHandler.java:44)
  9. [MJSONWP (c790c823)] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
  10. [MJSONWP (c790c823)] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
  11. [MJSONWP (c790c823)] at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)
  12. [MJSONWP (c790c823)] at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102)
  13. [MJSONWP (c790c823)] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
  14. [MJSONWP (c790c823)] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
  15. [MJSONWP (c790c823)] at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)
  16. [MJSONWP (c790c823)] at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:435)
  17. [MJSONWP (c790c823)] at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:293)
  18. [MJSONWP (c790c823)] at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:267)
  19. [MJSONWP (c790c823)] at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:250)
  20. [MJSONWP (c790c823)] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
  21. [MJSONWP (c790c823)] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
  22. [MJSONWP (c790c823)] at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)
  23. [MJSONWP (c790c823)] at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1294)
  24. [MJSONWP (c790c823)] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
  25. [MJSONWP (c790c823)] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
  26. [MJSONWP (c790c823)] at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:911)
  27. [MJSONWP (c790c823)] at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:131)
  28. [MJSONWP (c790c823)] at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:611)
  29. [MJSONWP (c790c823)] at io.netty.channel.nio.NioEventLoop.processSelectedKeysPlain(NioEventLoop.java:514)
  30. [MJSONWP (c790c823)] at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:468)
  31. [MJSONWP (c790c823)] at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:438)
  32. [MJSONWP (c790c823)] at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:140)
  33. [MJSONWP (c790c823)] at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:144)
  34. [MJSONWP (c790c823)] at java.lang.Thread.run(Thread.java:833)
  35. [MJSONWP (c790c823)]
  36. [MJSONWP (c790c823)] at errorFromMJSONWPStatusCode (C:\Users\m088163\AppData\Local\Programs\Appium\resources\app\node_modules\appium-base-driver\lib\protocol\errors.js:786:12)
  37. [MJSONWP (c790c823)] at ProxyRequestError.getActualError (C:\Users\m088163\AppData\Local\Programs\Appium\resources\app\node_modules\appium-base-driver\lib\protocol\errors.js:683:14)
  38. [MJSONWP (c790c823)] at JWProxy.command (C:\Users\m088163\AppData\Local\Programs\Appium\resources\app\node_modules\appium-base-driver\lib\jsonwp-proxy\proxy.js:234:19)
复制代码
然后我尝试定位下一级的每一个控件,然后输入密码,但还是显示是同一个错误。

第一个方法中,在Appium默认的模式下,也就是appium是可以输入内容的。
请问有什么方法可以在UIAutomator2模式下向非TextFiled控件进行sendKeys操作?。

项目环境
node.js version:v10.12.0
appium server version:v1.10.0
platform:Android
Android-Version:6.0



作者: litingting0214    时间: 2019-8-27 11:24
不太知道,坐等大神答案
作者: jingzizx    时间: 2019-8-27 12:25
之前都是输入的问题,只能换个别的方式




欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2