Appium [已解决] appium_iOS 使用自定义键盘输入问题

王明海 · 2016年07月20日 · 最后由 王明海 回复于 2016年07月25日 · 2750 次阅读

对于自定义键盘无法像系统键盘那样使用 Send Keys 进行输入,于是接下来想到的是把键盘当做普通控件处理,直接点击进行输入,以下面 app 界面为例

在文本框中输入股票代码 “600004”

def test_ihexin03(self):
    self.driver.find_element_by_accessibility_id("自选").click()
    self.driver.find_element_by_accessibility_id("搜索").click()
    sleep(2)

    # 点击键盘输入股票代码“600004”
    self.driver.find_element_by_accessibility_id("6").click()
    self.driver.find_element_by_accessibility_id("0").click()
    self.driver.find_element_by_accessibility_id("0").click()
    self.driver.find_element_by_accessibility_id("0").click()
    self.driver.find_element_by_accessibility_id("0").click()
    self.driver.find_element_by_accessibility_id("4").click()
    sleep(5)

终端报错

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #f5f5f5; background-color: #000000}p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #f5f5f5; background-color: #000000; min-height: 14.0px}span.s1 {font-variant-ligatures: no-common-ligatures}

HeminWon-Extranet:~ Hm$ python /Users/Hm/Desktop/ITestSwipe0713.py 
test_ihexin03 (__main__.ComplexIOSTests) ... ERROR

======================================================================
ERROR: test_ihexin03 (__main__.ComplexIOSTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/Hm/Desktop/ITestSwipe0713.py", line 69, in test_ihexin03
    self.driver.find_element_by_accessibility_id("6").click()
  File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webelement.py", line 72, in click
    self._execute(Command.CLICK_ELEMENT)
  File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webelement.py", line 461, in _execute
    return self._parent.execute(command, params)
  File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 236, in execute
    self.error_handler.check_response(response)
  File "build/bdist.macosx-10.11-intel/egg/appium/webdriver/errorhandler.py", line 29, in check_response
    raise wde
WebDriverException: Message: An unknown server-side error occurred while processing the command.

----------------------------------------------------------------------
Ran 1 test in 12.284s

FAILED (errors=1)

appium 关键日志

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Menlo; color: #00f900; background-color: #000000}p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Menlo; color: #ffffff; background-color: #000000; min-height: 14.0px}p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Menlo; color: #ffffff; background-color: #000000}p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Menlo; color: #fffb00; background-color: #000000}span.s1 {color: #00fdff}span.s2 {color: #ffffff}span.s3 {color: #00f900}span.s4 {color: #ff2600}

info: [debug] [INST] 2016-07-20 09:15:23 +0000 Debug: responding with:
info: [debug] [INST] 2016-07-20 09:15:23 +0000 Debug: Running system command #8: /Applications/Appium.app/Contents/Resources/node/bin/node /Applications/Appium.app/Contents/Resources/node_modules/appium/submodules/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":"5dbfa274-884f-4a91-8c57-dd325bcab8c2"}

info: <-- POST /wd/hub/session/5dbfa274-884f-4a91-8c57-dd325bcab8c2/element 200 1451.300 ms - 87 {"status":0,"value":{"ELEMENT":"2"},"sessionId":"5dbfa274-884f-4a91-8c57-dd325bcab8c2"}
info: --> POST /wd/hub/session/5dbfa274-884f-4a91-8c57-dd325bcab8c2/element/2/click {"sessionId":"5dbfa274-884f-4a91-8c57-dd325bcab8c2","id":"2"}
info: [debug] Pushing command to appium work queue: "au.tapById('2')"
info: [debug] Sending command to instruments: au.tapById('2')

info: [IOS_SYSLOG_ROW ] Jul 20 17:15:24 oumeikai MobileGestaltHelper[90] <Error>: libMobileGestalt MobileGestalt.c:281: server_access_check denied access to question UniqueDeviceID for pid 297

info: [IOS_SYSLOG_ROW ] Jul 20 17:15:24 oumeikai ScriptAgent[297] <Error>: libMobileGestalt MobileGestaltSupport.m:151: pid 297 (ScriptAgent) does not have sandbox access for re6Zb+zwFKJNlkQTUeT+/w and IS NOT appropriately entitled
info: [IOS_SYSLOG_ROW ] Jul 20 17:15:24 oumeikai ScriptAgent[297] <Error>: libMobileGestalt MobileGestalt.c:542: no access to UniqueDeviceID (see <rdar://problem/11744455>)
info: [IOS_SYSLOG_ROW ] Jul 20 17:15:24 oumeikai locationd[64] <Notice>: need a scan, count, 0, 0, lwatchdog, 0.0, interval, 60.0, needWatchdog, 0

info: [debug] [INST] 2016-07-20 09:15:24 +0000 Debug: Got new command 8 from instruments: au.tapById('2')
info: [debug] [INST] 2016-07-20 09:15:24 +0000 Debug: evaluating au.tapById('2')
info: [debug] [INST] 2016-07-20 09:15:24 +0000 Debug: UIAButton.tap()
info: [debug] [INST] 2016-07-20 09:15:24 +0000 Debug: UIAButton.scrollToVisible()
info: [debug] [INST] 2016-07-20 09:15:24 +0000 Debug: UIAButton - scrollToVisible cannot be used because this element has no scrollable ancestor.
info: [IOS_SYSLOG_ROW ] Jul 20 17:15:24 oumeikai MobileGestaltHelper[90] <Error>: libMobileGestalt MobileGestalt.c:281: server_access_check denied access to question UniqueDeviceID for pid 297
info: [IOS_SYSLOG_ROW ] Jul 20 17:15:24 oumeikai ScriptAgent[297] <Error>: libMobileGestalt MobileGestaltSupport.m:151: pid 297 (ScriptAgent) does not have sandbox access for re6Zb+zwFKJNlkQTUeT+/w and IS NOT appropriately entitled
info: [IOS_SYSLOG_ROW ] Jul 20 17:15:24 oumeikai ScriptAgent[297] <Error>: libMobileGestalt MobileGestalt.c:542: no access to UniqueDeviceID (see <rdar://problem/11744455>)
info: [debug] [INST] 2016-07-20 09:15:24 +0000 Debug: UIAButton - scrollToVisible cannot be used because this element has no scrollable ancestor.
info: [debug] [INST] 2016-07-20 09:15:24 +0000 Debug: UIAButton could not be tapped because the element is not visible

info: [debug] Socket data received (57 bytes)

info: [debug] Socket data being routed.
info: [debug] Got result from instruments: {"status":13,"value":"elementId 2 could not be tapped"}
info: [debug] Responding to client with error: {"status":13,"value":{"message":"An unknown server-side error occurred while processing the command.","origValue":"elementId 2 could not be tapped"},"sessionId":"5dbfa274-884f-4a91-8c57-dd325bcab8c2"}

info: <-- POST /wd/hub/session/5dbfa274-884f-4a91-8c57-dd325bcab8c2/element/2/click 500 1140.832 ms - 200 

info: --> DELETE /wd/hub/session/5dbfa274-884f-4a91-8c57-dd325bcab8c2 {}
info: Shutting down appium session
info: [debug] Stopping ios
info: [debug] Destroying instruments client socket.
info: [debug] Closing socket server.
info: [debug] Instruments socket server was closed
info: [debug] Sending sigterm to instruments
info: [debug] [INST] 2016-07-20 09:15:24 +0000 Error: VerboseError: elementId 2 could not be tapped

info: [debug] [INST] 2016-07-20 09:15:25 +0000 Error: Error during eval: [native code]
       file:///Applications/Appium.app/Contents/Resources/node_modules/appium/47041F0C-3B9E-48EB-9705-9FF11C85BD86/bootstrap-5923cadea0343e3f.js:711:30
tapById@file:///Applications/Appium.app/Contents/Resources/node_modules/appium/47041F0C-3B9E-48EB-9705-9FF11C85BD86/bootstrap-5923cadea0343e3f.js:1100:42
eval code
eval@[native code]
startProcessing@file:///Applications/Appium.app/Contents/Resources/node_modules/appium/47041F0C-3B9E-48EB-9705-9FF11C85BD86/bootstrap-5923cadea0343e3f.js:2710:30
bootstrap@file:///Applications/Appium.app/Contents/Resources/node_modules/appium/47041F0C-3B9E-48EB-9705-9FF11C85BD86/bootstrap-5923cadea0343e3f.js:2778:31
global code@file:///Applications/Appium.app/Contents/Resources/node_modules/appium/47041F0C-3B9E-48EB-9705-9FF11C85BD86/bootstrap-5923cadea0343e3f.js:2787:10

info: [debug] [INST] 2016-07-20 09:15:25 +0000 Debug: responding with:

info: [debug] [INST] 2016-07-20 09:15:25 +0000 Stopped: Script was stopped by the user

info: [IOS_SYSLOG_ROW ] Jul 20 17:15:25 oumeikai SpringBoard[58] <Warning>: HW kbd: Failed to set (null) as keyboard focus
info: [IOS_SYSLOG_ROW ] Jul 20 17:15:25 oumeikai SpringBoard[58] <Warning>: HW kbd: Failed to set (null) as keyboard focus
info: [IOS_SYSLOG_ROW ] Jul 20 17:15:25 oumeikai SpringBoard[58] <Warning>: UNNotificationRegistrarConnectionListener connection invalidated
info: [IOS_SYSLOG_ROW ] Jul 20 17:15:25 oumeikai com.apple.xpc.launchd[1] (UIKitApplication:cn.com.10jqka.IHexin[0x6d56][296]) <Notice>: Service exited due to signal: Killed: 9

info: [debug] [INST] 2016-07-20 09:15:25 +0000 Debug: Running system command #9: /Applications/Appium.app/Contents/Resources/node/bin/node /Applications/Appium.app/Contents/Resources/node_modules/appium/submodules/appium-uiauto/bin/command-proxy-client.js /tmp/instruments_sock 2,{"status":13,"value":"elementId 2 could not be tapped"}...
info: [debug] [INST STDERR] 2016-07-20 17:15:25.608 instruments[3035:25965] Attempting to change event horizon while disengage

info: [IOS_SYSLOG_ROW ] Jul 20 17:15:25 oumeikai SpringBoard[58] <Warning>: Application 'UIKitApplication:cn.com.10jqka.IHexin[0x6d56]' exited abnormally via signal.

info: [IOS_SYSLOG_ROW ] Jul 20 17:15:25 oumeikai UserEventAgent[26] <Warning>: 60966505040: id=cn.com.10jqka.IHexin pid=296, state=0

info: [debug] [INST] Instruments Trace Complete (Duration : 42.755268s; Output : /tmp/appium-instruments/instrumentscli0.trace)

info: [debug] [INSTSERVER] Instruments exited with code 0

info: [debug] Cleaning up after instruments exit
info: [debug] Stopping iOS log capture
info: [debug] Running ios sim reset flow
info: [debug] Killing the simulator process
info: [debug] Killing any other simulator daemons
info: [debug] Killall iOS Simulator

info: [debug] On a real device; cannot clean device state

info: [debug] Cleaning up appium session
info: [debug] Responding to client with success: {"status":0,"value":null,"sessionId":"5dbfa274-884f-4a91-8c57-dd325bcab8c2"}
info: <-- DELETE /wd/hub/session/5dbfa274-884f-4a91-8c57-dd325bcab8c2 200 1703.757 ms - 76 {"status":0,"value":null,"sessionId":"5dbfa274-884f-4a91-8c57-dd325bcab8c2"}

info: --> GET /wd/hub/status {}

问题原因?或者大家有更好的解决方法么

共收到 10 条回复 时间 点赞

用 setvalue 试试

#1 楼 @pacerron setvlaue 不行,好像说是安卓专用的方法,今天打算尝试另外一种解决方法

我可以啊 ,为什么不行 self._element.set_value(value_str)

这种自定义的控件 sendkeys 和 setvalue 是输入不了的,我的跟你一样的控件,你换 xpath 试试

#3 楼 @pacerron 嗯嗯,试了一下 set_value 报出下面的错误
脚本内容:

def test_ihexin03(self):
    self.driver.find_element_by_accessibility_id("自选").click()
    self.driver.find_element_by_accessibility_id("搜索").click()
    sleep(2)

    # 点击键盘输入股票代码“600004”
    #self.driver.find_element_by_accessibility_id("6").click()
    #self.driver.find_element_by_accessibility_id("0").click()
    #self.driver.find_element_by_accessibility_id("0").click()
    #self.driver.find_element_by_accessibility_id("0").click()
    #self.driver.find_element_by_accessibility_id("0").click()
    #self.driver.find_element_by_accessibility_id("0").click()
    #self.driver.find_element_by_accessibility_id("4").click()

    self.driver.set_value(60004)
    #el = self.driver.find_element_by_accessibility_id('6')
    #action = TouchAction(self.driver)
    #action.tap(el).perform()

    sleep(5)

终端报错:

HeminWon-Extranet:~ Hm$ python /Users/Hm/Desktop/ITestSwipe0713.py
test_ihexin03 (__main__.ComplexIOSTests) ... ERROR

======================================================================
ERROR: test_ihexin03 (__main__.ComplexIOSTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/Hm/Desktop/ITestSwipe0713.py", line 78, in test_ihexin03
    self.driver.set_value(60004)
TypeError: set_value() takes exactly 3 arguments (2 given)

----------------------------------------------------------------------
Ran 1 test in 33.931s

FAILED (errors=1)

app 关键日志:

info: --> POST /wd/hub/session/a163f8a2-c195-4d97-b157-0365368971ae/element {"using":"accessibility id","sessionId":"a163f8a2-c195-4d97-b157-0365368971ae","value":"自选"}
info: [debug] Waiting up to 0ms for condition
info: [debug] Pushing command to appium work queue: "au.getElementByAccessibilityId('自选')"
info: [debug] Sending command to instruments: au.getElementByAccessibilityId('自选')

info: [IOS_SYSLOG_ROW ] Jul 21 14:34:29 oumeikai IHexin[1495] <Warning>: DEBUG: setData: InstanceId=1, FrameId=2790, RealData=0

info: [debug] [INST] 2016-07-21 06:34:30 +0000 Debug: Got new command 3 from instruments: au.getElementByAccessibilityId('自选')

info: [debug] [INST] 2016-07-21 06:34:30 +0000 Debug: evaluating au.getElementByAccessibilityId('自选')

info: [debug] [INST] 2016-07-21 06:34:30 +0000 Debug: evaluation finished

info: [debug] [INST] 2016-07-21 06:34:30 +0000 Debug: Lookup returned [object UIAButton] with the name "自选" (id: 0).

info: [debug] [INST] 2016-07-21 06:34:30 +0000 Debug: responding with:
info: [debug] [INST] 2016-07-21 06:34:30 +0000 Debug: Running system command #4: /Applications/Appium.app/Contents/Resources/node/bin/node /Applications/Appium.app/Contents/Resources/node_modules/appium/submodules/appium-uiauto/bin/command-proxy-client.js /tmp/instruments_sock 2,{"status":0,"value":{"ELEMENT":"0"}}...

info: [debug] Socket data received (38 bytes)

info: [debug] Socket data being routed.
info: [debug] Got result from instruments: {"status":0,"value":{"ELEMENT":"0"}}
info: [debug] Responding to client with success: {"status":0,"value":{"ELEMENT":"0"},"sessionId":"a163f8a2-c195-4d97-b157-0365368971ae"}
info: <-- POST /wd/hub/session/a163f8a2-c195-4d97-b157-0365368971ae/element 200 1465.546 ms - 87 {"status":0,"value":{"ELEMENT":"0"},"sessionId":"a163f8a2-c195-4d97-b157-0365368971ae"}
info: --> POST /wd/hub/session/a163f8a2-c195-4d97-b157-0365368971ae/element/0/click {"sessionId":"a163f8a2-c195-4d97-b157-0365368971ae","id":"0"}
info: [debug] Pushing command to appium work queue: "au.tapById('0')"
info: [debug] Sending command to instruments: au.tapById('0')

info: [IOS_SYSLOG_ROW ] Jul 21 14:34:31 oumeikai MobileGestaltHelper[1409] <Error>: libMobileGestalt MobileGestalt.c:281: server_access_check denied access to question UniqueDeviceID for pid 1496

info: [IOS_SYSLOG_ROW ] Jul 21 14:34:31 oumeikai ScriptAgent[1496] <Error>: libMobileGestalt MobileGestaltSupport.m:151: pid 1496 (ScriptAgent) does not have sandbox access for re6Zb+zwFKJNlkQTUeT+/w and IS NOT appropriately entitled
info: [IOS_SYSLOG_ROW ] Jul 21 14:34:31 oumeikai ScriptAgent[1496] <Error>: libMobileGestalt MobileGestalt.c:542: no access to UniqueDeviceID (see <rdar://problem/11744455>)

info: [debug] [INST] 2016-07-21 06:34:31 +0000 Debug: Got new command 4 from instruments: au.tapById('0')

info: [debug] [INST] 2016-07-21 06:34:31 +0000 Debug: evaluating au.tapById('0')

info: [debug] [INST] 2016-07-21 06:34:31 +0000 Debug: UIAButton.tap()

info: [debug] [INST] 2016-07-21 06:34:31 +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":"a163f8a2-c195-4d97-b157-0365368971ae"}

info: <-- POST /wd/hub/session/a163f8a2-c195-4d97-b157-0365368971ae/element/0/click 200 1182.725 ms - 74 {"status":0,"value":"","sessionId":"a163f8a2-c195-4d97-b157-0365368971ae"}
info: --> POST /wd/hub/session/a163f8a2-c195-4d97-b157-0365368971ae/element {"using":"accessibility id","sessionId":"a163f8a2-c195-4d97-b157-0365368971ae","value":"搜索"}
info: [debug] Waiting up to 0ms for condition
info: [debug] Pushing command to appium work queue: "au.getElementByAccessibilityId('搜索')"
info: [debug] Sending command to instruments: au.getElementByAccessibilityId('搜索')
info: [debug] [INST] 2016-07-21 06:34:31 +0000 Debug: responding with:
info: [debug] [INST] 2016-07-21 06:34:31 +0000 Debug: Running system command #5: /Applications/Appium.app/Contents/Resources/node/bin/node /Applications/Appium.app/Contents/Resources/node_modules/appium/submodules/appium-uiauto/bin/command-proxy-client.js /tmp/instruments_sock 2,{"status":0,"value":""}...

info: [IOS_SYSLOG_ROW ] Jul 21 14:34:32 oumeikai IHexin[1495] <Warning>: DEBUG: RequestFlush: FrameId=2201, Content:

info: [IOS_SYSLOG_ROW ] [frame]
info: [IOS_SYSLOG_ROW ] id=2201
info: [IOS_SYSLOG_ROW ] pageList=10002,10006
info: [IOS_SYSLOG_ROW ] reqPage=10006
info: [IOS_SYSLOG_ROW ] reqPageCount=1
info: [IOS_SYSLOG_ROW ] [10006]
info: [IOS_SYSLOG_ROW ] id=1264
info: [IOS_SYSLOG_ROW ] startrow=0
info: [IOS_SYSLOG_ROW ] rowcount=17
info: [IOS_SYSLOG_ROW ] columnorder=55|10|34818|34821|48|13|34312|34311|34304|34305|49|7|6|8|9|53|34819|4|34393|34338|
info: [IOS_SYSLOG_ROW ] sortid=-1
info: [IOS_SYSLOG_ROW ] sortorder=1
info: [IOS_SYSLOG_ROW ] newrealtime=1

info: [IOS_SYSLOG_ROW ] Jul 21 14:34:32 oumeikai IHexin[1495] <Warning>: DEBUG: setData: InstanceId=10006, FrameId=2201, RealData=0

info: [IOS_SYSLOG_ROW ] Jul 21 14:34:32 oumeikai IHexin[1495] <Warning>: DEBUG: RequestImm: FrameId=9001, Content:

info: [IOS_SYSLOG_ROW ] Jul 21 14:34:32 oumeikai IHexin[1495] <Warning>: [frame]
info: [IOS_SYSLOG_ROW ] id=9001
info: [IOS_SYSLOG_ROW ] pageList=10002,10006,10007
info: [IOS_SYSLOG_ROW ] reqPage=10007
info: [IOS_SYSLOG_ROW ] reqPageCount=1
info: [IOS_SYSLOG_ROW ] [10007]
info: [IOS_SYSLOG_ROW ] id=1201

info: [IOS_SYSLOG_ROW ] Jul 21 14:34:32 oumeikai IHexin[1495] <Warning>: DEBUG: setData: InstanceId=10007, FrameId=2201, RealData=0

info: [debug] [INST] 2016-07-21 06:34:32 +0000 Debug: Got new command 5 from instruments: au.getElementByAccessibilityId('搜索')

info: [debug] [INST] 2016-07-21 06:34:32 +0000 Debug: evaluating au.getElementByAccessibilityId('搜索')

info: [debug] [INST] 2016-07-21 06:34:33 +0000 Debug: evaluation finished

info: [debug] [INST] 2016-07-21 06:34:33 +0000 Debug: Lookup returned [object UIAButton] with the name "搜索" (id: 1).

info: [debug] [INST] 2016-07-21 06:34:33 +0000 Debug: responding with:
info: [debug] [INST] 2016-07-21 06:34:33 +0000 Debug: Running system command #6: /Applications/Appium.app/Contents/Resources/node/bin/node /Applications/Appium.app/Contents/Resources/node_modules/appium/submodules/appium-uiauto/bin/command-proxy-client.js /tmp/instruments_sock 2,{"status":0,"value":{"ELEMENT":"1"}}...

info: [debug] Socket data received (38 bytes)

info: [debug] Socket data being routed.
info: [debug] Got result from instruments: {"status":0,"value":{"ELEMENT":"1"}}
info: [debug] Responding to client with success: {"status":0,"value":{"ELEMENT":"1"},"sessionId":"a163f8a2-c195-4d97-b157-0365368971ae"}

info: <-- POST /wd/hub/session/a163f8a2-c195-4d97-b157-0365368971ae/element 200 1581.437 ms - 87 {"status":0,"value":{"ELEMENT":"1"},"sessionId":"a163f8a2-c195-4d97-b157-0365368971ae"}
info: --> POST /wd/hub/session/a163f8a2-c195-4d97-b157-0365368971ae/element/1/click {"sessionId":"a163f8a2-c195-4d97-b157-0365368971ae","id":"1"}
info: [debug] Pushing command to appium work queue: "au.tapById('1')"
info: [debug] Sending command to instruments: au.tapById('1')

info: [IOS_SYSLOG_ROW ] Jul 21 14:34:34 oumeikai MobileGestaltHelper[1409] <Error>: libMobileGestalt MobileGestalt.c:281: server_access_check denied access to question UniqueDeviceID for pid 1496

info: [IOS_SYSLOG_ROW ] Jul 21 14:34:34 oumeikai ScriptAgent[1496] <Error>: libMobileGestalt MobileGestaltSupport.m:151: pid 1496 (ScriptAgent) does not have sandbox access for re6Zb+zwFKJNlkQTUeT+/w and IS NOT appropriately entitled
info: [IOS_SYSLOG_ROW ] Jul 21 14:34:34 oumeikai ScriptAgent[1496] <Error>: libMobileGestalt MobileGestalt.c:542: no access to UniqueDeviceID (see <rdar://problem/11744455>)

info: [debug] [INST] 2016-07-21 06:34:34 +0000 Debug: Got new command 6 from instruments: au.tapById('1')

info: [debug] [INST] 2016-07-21 06:34:34 +0000 Debug: evaluating au.tapById('1')

info: [debug] [INST] 2016-07-21 06:34:34 +0000 Debug: UIAButton.tap()

info: [debug] [INST] 2016-07-21 06:34:34 +0000 Debug: evaluation finished

info: [IOS_SYSLOG_ROW ] Jul 21 14:34:34 oumeikai IHexin[1495] <Warning>: StopRealData:

info: [IOS_SYSLOG_ROW ] Jul 21 14:34:34 oumeikai IHexin[1495] <Warning>: [frame]
info: [IOS_SYSLOG_ROW ] id=2201
info: [IOS_SYSLOG_ROW ] pageList=

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":"a163f8a2-c195-4d97-b157-0365368971ae"}
info: <-- POST /wd/hub/session/a163f8a2-c195-4d97-b157-0365368971ae/element/1/click 200 1271.332 ms - 74 {"status":0,"value":"","sessionId":"a163f8a2-c195-4d97-b157-0365368971ae"}

info: [IOS_SYSLOG_ROW ] Jul 21 14:34:35 oumeikai SpringBoard[58] <Warning>: [<_UIKeyboardArbiterHandle: 0x1307ac0e0; PID 177: (null) <(null)>; hosting PIDs {(

info: [IOS_SYSLOG_ROW ] )}; level 0.000000; active NO [wants NO]; suppression 0>] could not take process assertion

info: --> DELETE /wd/hub/session/a163f8a2-c195-4d97-b157-0365368971ae {}

info: Shutting down appium session
info: [debug] Stopping ios
info: [debug] Destroying instruments client socket.
info: [debug] Closing socket server.
info: [debug] Instruments socket server was closed
info: [debug] Sending sigterm to instruments

info: [debug] [INST] 2016-07-21 06:34:36 +0000 Stopped: Script was stopped by the user

info: [IOS_SYSLOG_ROW ] Jul 21 14:34:36 oumeikai SpringBoard[58] <Warning>: HW kbd: Failed to set (null) as keyboard focus

info: [IOS_SYSLOG_ROW ] Jul 21 14:34:36 oumeikai SpringBoard[58] <Warning>: HW kbd: Failed to set (null) as keyboard focus

info: [IOS_SYSLOG_ROW ] Jul 21 14:34:36 oumeikai SpringBoard[58] <Warning>: UNNotificationRegistrarConnectionListener connection invalidated
info: [IOS_SYSLOG_ROW ] Jul 21 14:34:36 oumeikai kbd[1350] <Warning>: __38-[TIWordSearch saveLearningDictionary]_block_invoke  Calling MecabraFlushDynamicData

info: [IOS_SYSLOG_ROW ] Jul 21 14:34:36 oumeikai com.apple.xpc.launchd[1] (UIKitApplication:cn.com.10jqka.IHexin[0x5316][1495]) <Notice>: Service exited due to signal: Killed: 9

info: [debug] [INST] 2016-07-21 06:34:34 +0000 Debug: responding with:
info: [debug] [INST] 2016-07-21 06:34:34 +0000 Debug: Running system command #7: /Applications/Appium.app/Contents/Resources/node/bin/node /Applications/Appium.app/Contents/Resources/node_modules/appium/submodules/appium-uiauto/bin/command-proxy-client.js /tmp/instruments_sock 2,{"status":0,"value":""}...

info: [debug] [INST STDERR] 2016-07-21 14:34:36.882 instruments[5634:135901] Attempting to change event horizon while disengage

info: [IOS_SYSLOG_ROW ] Jul 21 14:34:36 oumeikai SpringBoard[58] <Warning>: Application 'UIKitApplication:cn.com.10jqka.IHexin[0x5316]' exited abnormally via signal.

info: [IOS_SYSLOG_ROW ] Jul 21 14:34:36 oumeikai UserEventAgent[26] <Warning>: 1883645281118: id=cn.com.10jqka.IHexin pid=1495, state=0

info: [IOS_SYSLOG_ROW ] Jul 21 14:34:38 oumeikai locationd[64] <Notice>: need a scan, count, 0, 0, lwatchdog, 0.0, interval, 60.0, needWatchdog, 0

info: [debug] [INST] Instruments Trace Complete (Duration : 17.896297s; Output : /tmp/appium-instruments/instrumentscli0.trace)

info: [debug] [INSTSERVER] Instruments exited with code 0

info: [debug] Cleaning up after instruments exit
info: [debug] Stopping iOS log capture
info: [debug] Running ios sim reset flow
info: [debug] Killing the simulator process
info: [debug] Killing any other simulator daemons

info: [debug] Killall iOS Simulator

info: [debug] On a real device; cannot clean device state
info: [debug] Cleaning up appium session
info: [debug] Responding to client with success: {"status":0,"value":null,"sessionId":"a163f8a2-c195-4d97-b157-0365368971ae"}
info: <-- DELETE /wd/hub/session/a163f8a2-c195-4d97-b157-0365368971ae 200 2758.087 ms - 76 {"status":0,"value":null,"sessionId":"a163f8a2-c195-4d97-b157-0365368971ae"}

info: --> GET /wd/hub/status {}

请问下这个问题这么解决呢?

#4 楼 @fengliuyishao xpath 也是不行

#6 楼 @heminwon 看你用的苹果笔记本,最近想买本,做测试买苹果本行吗,怕软件不兼容

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

#6 楼 @heminwon 我的使用 xpath 一点问题也没啊,不过我为了兼容 Android 版本,根据控件自动计算出像素,另外我是用 java 写的,不知道是不是 appium 对 python api 的问题

#7 楼 @xuexi123 我做 iOS 这边的自动化,没有遇到什么兼容性问题

解决方法:不能直接 tap 元素,只能 tap 对应的坐标才会有效,所以选择封装一个 tap 的方法

class CustomDriver(webdriver.Remote):

    def hx_tap_element(self, element):
        location = element.location
        el_size = element.size
        return self.tap([(el_size['width'] / 2 + location['x'], el_size['height'] / 2 + location['y'],)])

    def hx_tap_element_with_name(self, name):
        el = self.find_element_by_name(name=name)
        return self.hx_tap_element(el)

    def hx_tap_element_with_name_sequence(self, sequence):
        return [self.hx_tap_element_with_name(name=name) for name in sequence]

    def hx_tap_element_with_name_args(self, *args):
        return [self.hx_tap_element_with_name(name=name) for name in args]
def test_ihexin03(self):
    self.driver.find_element_by_name("交易").click()
    self.driver.find_element_by_name("模拟炒股").click()
    #self.driver.find_element_by_name("买入").click()
    self.driver.find_element_by_xpath(
        " //UIAApplication[1]/UIAWindow[1]/UIAScrollView[1]/UIATableView[1]/UIATableCell[3]/UIAButton[1]").click()
    sleep(2)
    self.driver.find_element_by_xpath(
        "//UIAApplication[1]/UIAWindow[1]/UIAScrollView[1]/UIAScrollView[1]/UIATextField[1]").click()
    # sleep(2)
    # self.driver.hx_tap_element_with_name_sequence(('全仓', '1',))
    self.driver.hx_tap_element_with_name_sequence('600000')
    self.driver.find_element_by_xpath(
        "//UIAApplication[1]/UIAWindow[1]/UIAScrollView[1]/UIAScrollView[1]/UIATextField[3]").click()
    sleep(2)
    self.driver.hx_tap_element_with_name_args('全仓', '半仓', '2/3仓')

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