开发者社区> 问答> 正文

Appium 的 UIAutomator2 模式下使用 sendKeys 出现错误。

Appium 的 UIAutomator2 模式下使用 sendKeys 出现错误。

展开
收起
zxp-0601 2020-01-07 15:02:53 2191 0
1 条回答
写回答
取消 提交回答
  • 使用Appium做UI自动化测试,因为要获取到Toast信息,就用了UIAutomator2模式。登录App后,有一个设置6个密码的步骤。如下图

    上面有阴影的地方就是用来输入密码。布局如下图:

    我一开始的做法是想直接获取到“android.widget.LinearLayout” 然后输入6个数字的字符串。Appium能定位到元素的位置,但使用sendKey时候报了如下的错误: [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... [MJSONWP] Matched JSONWP error code 12 to InvalidElementStateError [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? [MJSONWP (c790c823)] at io.appium.uiautomator2.handler.SendKeysToElement.safeHandle(SendKeysToElement.java:96) [MJSONWP (c790c823)] at io.appium.uiautomator2.handler.request.SafeRequestHandler.handle(SafeRequestHandler.java:37) [MJSONWP (c790c823)] at io.appium.uiautomator2.server.AppiumServlet.handleRequest(AppiumServlet.java:250) [MJSONWP (c790c823)] at io.appium.uiautomator2.server.AppiumServlet.handleHttpRequest(AppiumServlet.java:241) [MJSONWP (c790c823)] at io.appium.uiautomator2.http.ServerHandler.channelRead(ServerHandler.java:44) [MJSONWP (c790c823)] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366) [MJSONWP (c790c823)] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352) [MJSONWP (c790c823)] at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345) [MJSONWP (c790c823)] at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102) [MJSONWP (c790c823)] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366) [MJSONWP (c790c823)] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352) [MJSONWP (c790c823)] at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345) [MJSONWP (c790c823)] at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:435) [MJSONWP (c790c823)] at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:293) [MJSONWP (c790c823)] at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:267) [MJSONWP (c790c823)] at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:250) [MJSONWP (c790c823)] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366) [MJSONWP (c790c823)] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352) [MJSONWP (c790c823)] at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345) [MJSONWP (c790c823)] at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1294) [MJSONWP (c790c823)] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366) [MJSONWP (c790c823)] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352) [MJSONWP (c790c823)] at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:911) [MJSONWP (c790c823)] at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:131) [MJSONWP (c790c823)] at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:611) [MJSONWP (c790c823)] at io.netty.channel.nio.NioEventLoop.processSelectedKeysPlain(NioEventLoop.java:514) [MJSONWP (c790c823)] at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:468) [MJSONWP (c790c823)] at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:438) [MJSONWP (c790c823)] at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:140) [MJSONWP (c790c823)] at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:144) [MJSONWP (c790c823)] at java.lang.Thread.run(Thread.java:833) [MJSONWP (c790c823)] [MJSONWP (c790c823)] at errorFromMJSONWPStatusCode (C:\Users\m088163\AppData\Local\Programs\Appium\resources\app\node_modules\appium-base-driver\lib\protocol\errors.js:786:12) [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) [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

    2020-01-07 15:03:17
    赞同 展开评论 打赏
问答标签:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载