self.driver.find_element_by_xpath("//android.widget.EditText[@text='请输入工号']").click()
self.driver.find_element_by_xpath("//android.widget.EditText[@text='请输入工号']").send_keys("15112319")

点击事件可以操作成功,但是输入事件报错,报错如下:

[HTTP] --> POST /wd/hub/session/b444d990-4abe-42f7-972a-6e1f39c0eeff/element/e132143d-d48d-4dc4-9135-bbd4ebc7e2a2/value
[HTTP] {"text":"15112319","value":["1","5","1","1","2","3","1","9"],"id":"e132143d-d48d-4dc4-9135-bbd4ebc7e2a2"}
[W3C (b444d990)] Calling AppiumDriver.setValue() with args: [["1","5","1","1","2","3","1","9"],"e132143d-d48d-4dc4-9135-bbd4ebc7e2a2","b444d990-4abe-42f7-972a-6e1f39c0eeff"]
[WD Proxy] Matched '/element/e132143d-d48d-4dc4-9135-bbd4ebc7e2a2/value' to command name 'setValue'
[Protocol Converter] Added 'value' property ["1","5","1","1","2","3","1","9"] to 'setValue' request body
[WD Proxy] Proxying [POST /element/e132143d-d48d-4dc4-9135-bbd4ebc7e2a2/value] to [POST http://127.0.0.1:8200/wd/hub/session/37c0ad39-0fb1-4ae3-b6a0-54d332108d9a/element/e132143d-d48d-4dc4-9135-bbd4ebc7e2a2/value] with body: {"elementId":"e132143d-d48d-4dc4-9135-bbd4ebc7e2a2","text":"15112319","replace":false,"value":["1","5","1","1","2","3","1","9"]}
[WD Proxy] Got response with status 400: {"sessionId":"37c0ad39-0fb1-4ae3-b6a0-54d332108d9a","value":{"error":"invalid element state","message":"Cannot set the element to '15112319'. Did you interact with the correct element?","stacktrace":"io.appium.uiautomator2.common.exceptions.InvalidElementStateException: Cannot set the element to '15112319'. Did you interact with the correct element?\n\tat io.appium.uiautomator2.handler.SendKeysToElement.setText(SendKeysToElement.java:88)\n\tat io.appium.uiautomator2.handler.SendKeysToElement.safeHandle(SendKeysToElement.java:119)\n\tat io.appium.uiautomator2.handler.request.SafeRequestHandler.handle(SafeRequestHandler.java:41)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleRequest(AppiumServlet.java:253)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleHttpRequest(AppiumServlet.java:247)\n\tat io.appium.uiautomator2.http.ServerHandler.channelRead(ServerHandler.java:68)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)\n\tat io.net...
[W3C] Matched W3C error code 'invalid element state' to InvalidElementStateError
[W3C (b444d990)] Encountered internal error running command: io.appium.uiautomator2.common.exceptions.InvalidElementStateException: Cannot set the element to '15112319'. Did you interact with the correct element?
[W3C (b444d990)] at io.appium.uiautomator2.handler.SendKeysToElement.setText(SendKeysToElement.java:88)
[W3C (b444d990)] at io.appium.uiautomator2.handler.SendKeysToElement.safeHandle(SendKeysToElement.java:119)
[W3C (b444d990)] at io.appium.uiautomator2.handler.request.SafeRequestHandler.handle(SafeRequestHandler.java:41)
[W3C (b444d990)] at io.appium.uiautomator2.server.AppiumServlet.handleRequest(AppiumServlet.java:253)
[W3C (b444d990)] at io.appium.uiautomator2.server.AppiumServlet.handleHttpRequest(AppiumServlet.java:247)
[W3C (b444d990)] at io.appium.uiautomator2.http.ServerHandler.channelRead(ServerHandler.java:68)
[W3C (b444d990)] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
[W3C (b444d990)] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
[W3C (b444d990)] at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)
[W3C (b444d990)] at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102)
[W3C (b444d990)] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
[W3C (b444d990)] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
[W3C (b444d990)] at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)
[W3C (b444d990)] at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:435)
[W3C (b444d990)] at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:293)
[W3C (b444d990)] at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:267)
[W3C (b444d990)] at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:250)
[W3C (b444d990)] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
[W3C (b444d990)] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
[W3C (b444d990)] at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)
[W3C (b444d990)] at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:266)
[W3C (b444d990)] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
[W3C (b444d990)] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
[W3C (b444d990)] at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)
[W3C (b444d990)] at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1294)
[W3C (b444d990)] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
[W3C (b444d990)] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
[W3C (b444d990)] at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:911)
[W3C (b444d990)] at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:131)
[W3C (b444d990)] at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:611)
[W3C (b444d990)] at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:552)
[W3C (b444d990)] at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:466)
[W3C (b444d990)] at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:438)
[W3C (b444d990)] at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:140)
[W3C (b444d990)] at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:144)
[W3C (b444d990)] at java.lang.Thread.run(Thread.java:929)
[W3C (b444d990)]


↙↙↙阅读原文可查看相关链接,并与作者交流