每周问答 执行 SendKey 方法是会间歇性的出现失败情况

Acacia1986 · 2015年02月16日 · 2164 次阅读

appium 1.3.4

部分脚本:
capabilities.setCapability("autoAcceptAlerts", true);
capabilities.setCapability("resetKeyboard", true);
capabilities.setCapability("unicodeKeyboard", true);
capabilities.setCapability("full-reset", true);
driver = new IOSDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
报错脚本 1:
MobileElement mobileNumber = (MobileElement) driver.findElement(By.xpath("//UIAApplication[1]/UIAWindow[1]/UIATextField[1]"));

mobileNumber.sendKeys("13818181818");
报错脚本 2:
MobileElement sms_verify1 = (MobileElement) driver.findElement(By.xpath("//UIAApplication[1]/UIAWindow[1]/UIATextField[1]"));
sms_verify1.sendKeys("8");
MobileElement sms_verify2 = (MobileElement) driver.findElement(By.xpath("//UIAApplication[1]/UIAWindow[1]/UIATextField[2]"));
sms_verify2.sendKeys("8");

MobileElement sms_verify3 = (MobileElement) driver.findElement(By.xpath("//UIAApplication[1]/UIAWindow[1]/UIATextField[3]"));
sms_verify3.sendKeys("8");
MobileElement sms_verify4 = (MobileElement) driver.findElement(By.xpath("//UIAApplication[1]/UIAWindow[1]/UIATextField[4]"));
sms_verify4.sendKeys("8");

报错内容:
Exception in thread "main" org.openqa.selenium.WebDriverException: An error occurred while executing user supplied JavaScript. (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 2.34 seconds

问题描述:
在尝试想 text 组件中输入内容时,会间歇性的发生错误,虽然配置了 resetKeyBoard,但是观察到键盘总会有不弹出的现象,导致用 sendKeys 失败报错,但有时又可以正常运行。使用 setValue 虽然不报错,但 app 会不继续执行。想请问一下是否有其他解决方案。

共收到 4 条回复 时间 点赞

请增加头像和使用 markdown,提醒一次

能附上 Appium 端的错误信息吗?

Appium Log 如下:
info: [debug] Socket data received (5277 bytes)
info: [debug] Socket data being routed.
info: [debug] Got result from instruments: {"status":0,"value":{"UIAApplication":{"@":{"name":"ä¿æ¶æ·ä¸äº«","label":"ä¿æ¶æ·ä¸äº«","value":null,"dom":null,"enabled":true,"valid":true,"visible":true,"hint":null,"path":"/0","x":0,"y":20,"width":320,"height":460},">":[{"UIAWindow":{"@":{"name":null,"label":null,"value":null,"dom":n
info: [debug] Pushing command to appium work queue: "au.getElementByIndexPath('/0/0/3')"
info: [debug] Sending command to instruments: au.getElementByIndexPath('/0/0/3')
info: [debug] [INST] 2015-02-17 01:29:24 +0000 Debug: Got new command 10 from instruments: au.getElementByIndexPath('/0/0/3')
info: [debug] [INST] 2015-02-17 01:29:24 +0000 Debug: evaluating au.getElementByIndexPath('/0/0/3')
info: [debug] [INST] 2015-02-17 01:29:24 +0000 Debug: evaluation finished
info: [debug] [INST] 2015-02-17 01:29:24 +0000 Debug: responding with:
info: [debug] [INST] 2015-02-17 01:29:24 +0000 Debug: Running system command #11: /usr/local/bin/node /usr/local/lib/node_modules/appium/node_modules/appium-uiauto/bin/command-proxy-client.js /tmp/instruments_sock 2,{"status":0,"value":{"ELEMENT":"2"}}...
info: [debug] Socket data received (38 bytes)
info: [debug] Socket data being routed.
info: [debug] Got result from instruments: {"status":0,"value":{"ELEMENT":"2"}}
info: [debug] Responding to client with success: {"status":0,"value":{"ELEMENT":"2"},"sessionId":"a62806fe-f705-4586-ba69-77f9e452d81c"}
info: <-- POST /wd/hub/session/a62806fe-f705-4586-ba69-77f9e452d81c/element 200 2047.369 ms - 87 {"status":0,"value":{"ELEMENT":"2"},"sessionId":"a62806fe-f705-4586-ba69-77f9e452d81c"}
info: --> POST /wd/hub/session/a62806fe-f705-4586-ba69-77f9e452d81c/element/2/clear {"id":"2"}
info: [debug] Pushing command to appium work queue: "au.getElement('2').setValue('')"
info: [debug] Sending command to instruments: au.getElement('2').setValue('')
info: [debug] [INST] 2015-02-17 01:29:27 +0000 Debug: Got new command 11 from instruments: au.getElement('2').setValue('')
info: [debug] [INST] 2015-02-17 01:29:27 +0000 Debug: evaluating au.getElement('2').setValue('')
info: [debug] [INST] 2015-02-17 01:29:27 +0000 Debug: target.frontMostApp().elements()[0].elements()[3].tap()
info: [debug] [INST] 2015-02-17 01:29:28 +0000 Debug: evaluation finished
info: [debug] Socket data received (25 bytes)
info: [debug] Socket data being routed.
info: [debug] Got result from instruments: {"status":0,"value":""}
info: [debug] Responding to client with success: {"status":0,"value":"","sessionId":"a62806fe-f705-4586-ba69-77f9e452d81c"}
info: <-- POST /wd/hub/session/a62806fe-f705-4586-ba69-77f9e452d81c/element/2/clear 200 1547.627 ms - 74 {"status":0,"value":"","sessionId":"a62806fe-f705-4586-ba69-77f9e452d81c"}
info: --> POST /wd/hub/session/a62806fe-f705-4586-ba69-77f9e452d81c/element/2/value {"id":"2","value":["13818181818"]}
info: [debug] Pushing command to appium work queue: "au.getElement('2').setValueByType('13818181818')"
info: [debug] Sending command to instruments: au.getElement('2').setValueByType('13818181818')
info: [debug] [INST] 2015-02-17 01:29:28 +0000 Debug: responding with:
info: [debug] [INST] 2015-02-17 01:29:28 +0000 Debug: Running system command #12: /usr/local/bin/node /usr/local/lib/node_modules/appium/node_modules/appium-uiauto/bin/command-proxy-client.js /tmp/instruments_sock 2,{"status":0,"value":""}...
info: [debug] [INST] 2015-02-17 01:29:29 +0000 Debug: Got new command 12 from instruments: au.getElement('2').setValueByType('13818181818')
info: [debug] [INST] 2015-02-17 01:29:29 +0000 Debug: evaluating au.getElement('2').setValueByType('13818181818')
info: [debug] [INST] 2015-02-17 01:29:29 +0000 Debug: target.frontMostApp().keyboard().typeString("1")
info: [debug] [INST] 2015-02-17 01:29:30 +0000 Debug: target.frontMostApp().keyboard() failed to tap '1'
info: [debug] [INST] 2015-02-17 01:29:30 +0000 Debug: Error typing '1': VerboseError: target.frontMostApp().keyboard() failed to tap '1'
info: [debug] [INST] 2015-02-17 01:29:30 +0000 Debug: Retrying...
info: [debug] [INST] 2015-02-17 01:29:30 +0000 Debug: target.frontMostApp().keyboard().typeString("1")
info: [debug] [INST] 2015-02-17 01:29:30 +0000 Debug: target.frontMostApp().keyboard() failed to tap '1'
info: [debug] Socket data received (76 bytes)
info: [debug] Socket data being routed.
info: [debug] Got result from instruments: {"status":17,"value":"target.frontMostApp().keyboard() failed to tap '1'"}
info: [debug] Responding to client with error: {"status":17,"value":{"message":"An error occurred while executing user supplied JavaScript.","origValue":"target.frontMostApp().keyboard() failed to tap '1'"},"sessionId":"a62806fe-f705-4586-ba69-77f9e452d81c"}
info: <-- POST /wd/hub/session/a62806fe-f705-4586-ba69-77f9e452d81c/element/2/value 500 2148.613 ms - 211
info: [debug] [INST] 2015-02-17 01:29:30 +0000 Error: VerboseError: target.frontMostApp().keyboard() failed to tap '1'
info: [debug] [INST] 2015-02-17 01:29:30 +0000 Error: Error during eval: typeString@[native code]
sendKeysToActiveElement@file:///usr/local/lib/node_modules/appium/87825093-A08D-4163-9A35-BD32B808337B/bootstrap-65e0b16df0e74810.js:1266:32
setValueByType@file:///usr/local/lib/node_modules/appium/87825093-A08D-4163-9A35-BD32B808337B/bootstrap-65e0b16df0e74810.js:1964:38
eval code
eval@[native code]
startProcessing@file:///usr/local/lib/node_modules/appium/87825093-A08D-4163-9A35-BD32B808337B/bootstrap-65e0b16df0e74810.js:2663:30
bootstrap@file:///usr/local/lib/node_modules/appium/87825093-A08D-4163-9A35-BD32B808337B/bootstrap-65e0b16df0e74810.js:2729:31
global code@file:///usr/local/lib/node_modules/appium/87825093-A08D-4163-9A35-BD32B808337B/bootstrap-65e0b16df0e74810.js:2738:10
info: [debug] [INST] 2015-02-17 01:29:30 +0000 Debug: responding with:
info: [debug] [INST] 2015-02-17 01:29:30 +0000 Debug: Running system command #13: /usr/local/bin/node /usr/local/lib/node_modules/appium/node_modules/appium-uiauto/bin/command-proxy-client.js /tmp/instruments_sock 2,{"status":17,"value":"target.frontMostApp().keyboard() failed to tap '1'"}...

匿名 #4 · 2015年02月18日

是不是得加点等待时间,,

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册