大家有没有遇见这样一个现象:
调用 send_keys 时,在界面上向一个编辑区域写入字符(A 区);在相同界面接下来下一个编辑区域写入字符(B 区),在 B 区 写入字符前,会删除 A 区 已经写入的字符内容
代码如下:
#开始创建任务
#---------------------下面是A区域写入字符---------------------
##点击名称,输入任务的名称信息
time.sleep(2)
plan_name_edit = driver.find_element_by_id('com.xxx.phone:id/plan_name_edit')
task_name = 'autoTestMobileTask_' + str(randAlpha(6))
logging.info("点击名称,输入任务的名称: " + task_name + ".\n")
plan_name_edit.send_keys(task_name)
#---------------------下面是对B区域写入字符---------------------
##点击描述,输入任务的描述信息
time.sleep(5)
desc_edit = driver.find_element_by_id('com.xxx.phone:id/plan_description_edit')
desc_info = randLowAscii(60)
logging.info("点击描述,输入任务的描述信息: " + desc_info + ".\n")
desc_edit.send_keys(desc_info)
日志片段如下:
info: [debug] [BOOTSTRAP] [debug] Finding com.xxx.phone:id/plan_name_edit u
sing ID with the contextId: multiple: false
info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[INSTANCE=0, RESOURCE_ID=com.
xxx.phone:id/plan_name_edit]
info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":{"ELEMENT":"3"},"st
atus":0}
info: [debug] Responding to client with success: {"status":0,"value":{"ELEMENT":
"3"},"sessionId":"6ddea56b-d162-4e8f-8eed-a04702f9ec4c"}
info: <-- POST /wd/hub/session/6ddea56b-d162-4e8f-8eed-a04702f9ec4c/element 200
33.947 ms - 87 {"status":0,"value":{"ELEMENT":"3"},"sessionId":"6ddea56b-d162-4e
8f-8eed-a04702f9ec4c"}
info: --> POST /wd/hub/session/6ddea56b-d162-4e8f-8eed-a04702f9ec4c/element/3/va
lue {"sessionId":"6ddea56b-d162-4e8f-8eed-a04702f9ec4c","id":"3","value":["a","u
","t","o","T","e","s","t","M","o","b","i","l","e","T","a","s","k","_","9","2","3
","7","4","0"]}
info: [debug] Pushing command to appium work queue: ["element:setText",{"element
Id":"3","text":"autoTestMobileTask_923740","replace":false}]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action"
:"element:setText","params":{"elementId":"3","text":"autoTestMobileTask_923740",
"replace":false}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: setText
info: [debug] [BOOTSTRAP] [debug] Attempting to clear using UiObject.clearText()
.
info: [debug] [BOOTSTRAP] [debug] Updating class "class com.android.uiautomator.
core.UiDevice" to enable field "mUiAutomationBridge"
info: [debug] [BOOTSTRAP] [debug] Updating class "class com.android.uiautomator.
core.UiAutomatorBridge" to enable field "mInteractionController"
info: [debug] [BOOTSTRAP] [debug] Finding methods on class: class com.android.ui
automator.core.InteractionController
info: [debug] [BOOTSTRAP] [debug] Text remains after clearing, but it appears to
be hint text.
info: [debug] [BOOTSTRAP] [debug] Text not cleared. Assuming remainder is hint t
ext.
info: [debug] [BOOTSTRAP] [debug] Sending plain text to element: autoTestMobileT
ask_923740
info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":true,"status":0}
info: [debug] Responding to client with success: {"status":0,"value":true,"sessi
onId":"6ddea56b-d162-4e8f-8eed-a04702f9ec4c"}
info: <-- POST /wd/hub/session/6ddea56b-d162-4e8f-8eed-a04702f9ec4c/element/3/va
lue 200 6936.020 ms - 76 {"status":0,"value":true,"sessionId":"6ddea56b-d162-4e8
f-8eed-a04702f9ec4c"}
info: --> POST /wd/hub/session/6ddea56b-d162-4e8f-8eed-a04702f9ec4c/element {"us
ing":"id","sessionId":"6ddea56b-d162-4e8f-8eed-a04702f9ec4c","value":"com.xxx.ph
one:id/plan_description_edit"}
info: [debug] Waiting up to 10000ms for condition
info: [debug] Pushing command to appium work queue: ["find",{"strategy":"id","se
lector":"com.xxx.phone:id/plan_description_edit","context":"","multiple":fa
lse}]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action"
:"find","params":{"strategy":"id","selector":"com.xxx.phone:id/plan_descrip
tion_edit","context":"","multiple":false}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: find
info: [debug] [BOOTSTRAP] [debug] Finding com.xxx.phone:id/plan_description
_edit using ID with the contextId: multiple: false
info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[INSTANCE=0, RESOURCE_ID=com.
xxx.phone:id/plan_description_edit]
info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":{"ELEMENT":"4"},"st
atus":0}
info: [debug] Responding to client with success: {"status":0,"value":{"ELEMENT":
"4"},"sessionId":"6ddea56b-d162-4e8f-8eed-a04702f9ec4c"}
info: <-- POST /wd/hub/session/6ddea56b-d162-4e8f-8eed-a04702f9ec4c/element 200
40.074 ms - 87 {"status":0,"value":{"ELEMENT":"4"},"sessionId":"6ddea56b-d162-4e
8f-8eed-a04702f9ec4c"}
info: --> POST /wd/hub/session/6ddea56b-d162-4e8f-8eed-a04702f9ec4c/element/4/va
lue {"sessionId":"6ddea56b-d162-4e8f-8eed-a04702f9ec4c","id":"4","value":["j","d
","z","f","l","z","v","z","a","x","m","e","p","q","y","b","t","l","g","b","i","e
","x","n","x","m","u","l","g","l","g","b","e","f","f","j","f","r","x","h","q","g
","o","z","i","d","l","y","v","l","g","o","m","r","u","v","c","v","v","e"]}
info: [debug] Pushing command to appium work queue: ["element:setText",{"element
Id":"4","text":"jdzflzvzaxmepqybtlgbiexnxmulglgbeffjfrxhqgozidlyvlgomruvcvve","r
eplace":false}]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action"
:"element:setText","params":{"elementId":"4","text":"jdzflzvzaxmepqybtlgbiexnxmu
lglgbeffjfrxhqgozidlyvlgomruvcvve","replace":false}}
现象是:
A 区域一开始写入的内容为: autoTestMobileTask_923740,接着要往 B 区域写入内容,在 B 区域写入内容前,A 区域写入内容后,这一段时间内,发生了这么一个事情:
A 区域已经写入的内容 autoTestMobileTask_923740,会被删除掉 7 和 0 两个数字,截图如下: