Appium 的 UIAutomator2 模式下使用 sendKeys 出现错误。
使用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
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。