Appium 新手请教一个输入的问题:控件找到了,却输入不进去

骆小C · 2016年07月01日 · 最后由 cloudwind 回复于 2016年08月01日 · 1410 次阅读

appium 版本 1.4.16.1
输入用户名和密码,用 find_element_by_xpath 找到了控件,然后 click 没问题,然后输入文本却不行了,最后报错说找不到控件
python 代码如下:
# 输入用户名
name=self.driver.find_element_by_xpath(
'//android.widget.LinearLayout[contains(@index,5)]/android.widget.RelativeLayout[contains(@index,0)]/android.widget.RelativeLayout[contains(@index,2)]/android.widget.EditText')
name.click()
time.sleep(1)
name.send_keys('10103687')
time.sleep(1)

appium 运行报错:

info: [debug] [BOOTSTRAP] [debug] Finding //android.widget.LinearLayout[contains(@index,5)]/android.widget.RelativeLayout[contains(@index,0)]/android.widget.RelativeLayout[contains(@index,2)]/android.widget.EditText using XPATH with the contextId: multiple: false
info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[CLASS=android.widget.EditText, INSTANCE=0]
info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":{"ELEMENT":"4"},"status":0}
info: [debug] Responding to client with success: {"status":0,"value":{"ELEMENT":"4"},"sessionId":"8bd7be54-a532-49ce-bb06-6f58b7602bae"}
info: <-- POST /wd/hub/session/8bd7be54-a532-49ce-bb06-6f58b7602bae/element 200 279.505 ms - 87 {"status":0,"value":{"ELEMENT":"4"},"sessionId":"8bd7be54-a532-49ce-bb06-6f58b7602bae"}
info: --> POST /wd/hub/session/8bd7be54-a532-49ce-bb06-6f58b7602bae/element/4/click {"sessionId":"8bd7be54-a532-49ce-bb06-6f58b7602bae","id":"4"}
info: [debug] Pushing command to appium work queue: ["element:click",{"elementId":"4"}]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"element:click","params":{"elementId":"4"}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: click
info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":true,"status":0}
info: [debug] Responding to client with success: {"status":0,"value":true,"sessionId":"8bd7be54-a532-49ce-bb06-6f58b7602bae"}
info: <-- POST /wd/hub/session/8bd7be54-a532-49ce-bb06-6f58b7602bae/element/4/click 200 433.828 ms - 76 {"status":0,"value":true,"sessionId":"8bd7be54-a532-49ce-bb06-6f58b7602bae"}
info: --> POST /wd/hub/session/8bd7be54-a532-49ce-bb06-6f58b7602bae/element/4/value {"sessionId":"8bd7be54-a532-49ce-bb06-6f58b7602bae","id":"4","value":["1","0","1","0","3","6","8","7"]}
info: [debug] Pushing command to appium work queue: ["element:setText",{"elementId":"4","text":"10103687","replace":false}]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"element:setText","params":{"elementId":"4","text":"10103687","replace":false}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: setText
info: [debug] [BOOTSTRAP] [debug] Using element passed in.
info: [debug] [BOOTSTRAP] [debug] Attempting to clear using UiObject.clearText().
info: [debug] Didn't get a new command in 30 secs, shutting down...
info: Shutting down appium session
info: [debug] Pressing the HOME button
info: [debug] executing cmd: C:\android-sdk-windows\platform-tools\adb.exe -s 5202c0a74d622100 shell "input keyevent 3"
info: [debug] Stopping logcat capture
info: [debug] Logcat terminated with code null, signal SIGTERM
warn: Trying to run a command when one is already in progress. Will spin a bit and try again
info: [debug] Sent shutdown command, waiting for UiAutomator to stop...
info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":"UiSelector[CLASS=android.widget.EditText, INSTANCE=0]","status":7}
info: [debug] Responding to client with error: {"status":7,"value":{"message":"An element could not be located on the page using the given search parameters.","origValue":"UiSelector[CLASS=android.widget.EditText, INSTANCE=0]"},"sessionId":null}
info: <-- POST /wd/hub/session/8bd7be54-a532-49ce-bb06-6f58b7602bae/element/4/value 500 43647.594 ms - 198
warn: UiAutomator did not shut down fast enough, calling it gone
info: [debug] Cleaning up android objects
info: [debug] Cleaning up appium session
info: [debug] We shut down because no new commands came in

手机上可以看到,点击进了用户名输入框,下面的输入法也出来了,然后就是没有输入任何字符,过了一会儿,输入框上面显示了 “粘贴”,但是也没有粘贴进去。

'unicodeKeyboard': 'True',
'resetKeyboard': 'True'
上面这两个 unicodeKeyboard 参数加上也不行,还是一样的错

另外还试过在这个 app 的其它地方输入同样的文本,却没问题。就是输入用户名和密码这个地方不行。
下面是 uiautomatorviewer 该控件的截图

共收到 7 条回复 时间 点赞

关键 log :

info: [debug] [BOOTSTRAP] [debug] Attempting to clear using UiObject.clearText().
info: [debug] Didn't get a new command in 30 secs, shutting down...
info: Shutting down appium session
info: [debug] Pressing the HOME button

进行 clearText 的时候卡住了,但也没什么错误提示。。。
建议你先试试换台设备,看还有没有问题。有可能是设备本身的问题。clearText 在界面上表现应该是长按输入框,全选所有内容,然后直接删除。

PS:你的 xpath 有点奇怪,第一次见 contains(@index,5) 这种语法,一般都是直接 @index=5 或者直接就是 EditText[5]

#1 楼 @chenhengjie123 contains 是可以的。。模糊匹配

楼主的这问题我也遇到过,你的 app 是原生开发的还是混合开发?我出现这个问题的时候当时是因为我们的 app 不是原生开发,而是混合开发,例如 QT+QML 这种架构,由于当时 app 中引用 QT 自带的键盘库导致点击文本框后键盘吊起来了,但是却看不到输入的内容,最后换了键盘库后就解决了这个问题。

换了台手机,正常了。。。感谢各位!

是什么原因呀,我也遇到同样的问题。 在小米手机中可以输入,但是荣耀中就输入不进去

@suifeng 你换成哪种键盘库了?

英文的话可以用 keycode,中文的话可以用 UITest7 输入法配合

—— 来自 TesterHome 官方 安卓客户端

cloudwind [该话题已被删除] 中提及了此贴 08月01日 11:08
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册