Appium 的 UIAutomator2 模式下使用 sendKeys 出现错误。
问题描述使用Appium做UI自动化测试,因为要获取到Toast信息,就用了UIAutomator2模式。登录App后,有一个设置6个密码的步骤。如下图
上面有阴影的地方就是用来输入密码。布局如下图:
我一开始的做法是想直接获取到“android.widget.LinearLayout” 然后输入6个数字的字符串。Appium能定位到元素的位置,但使用sendKey时候报了如下的错误:
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...
Matched JSONWP error code 12 to InvalidElementStateError
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?
at io.appium.uiautomator2.handler.SendKeysToElement.safeHandle(SendKeysToElement.java:96)
at io.appium.uiautomator2.handler.request.SafeRequestHandler.handle(SafeRequestHandler.java:37)
at io.appium.uiautomator2.server.AppiumServlet.handleRequest(AppiumServlet.java:250)
at io.appium.uiautomator2.server.AppiumServlet.handleHttpRequest(AppiumServlet.java:241)
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:833)
at errorFromMJSONWPStatusCode (C:\Users\m088163\AppData\Local\Programs\Appium\resources\app\node_modules\appium-base-driver\lib\protocol\errors.js:786:12)
at ProxyRequestError.getActualError (C:\Users\m088163\AppData\Local\Programs\Appium\resources\app\node_modules\appium-base-driver\lib\protocol\errors.js:683:14)
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
不太知道,坐等大神答案 之前都是输入的问题,只能换个别的方式
页:
[1]