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 该控件的截图