appium_iOS使用自定義鍵盤輸入問(wèn)題

對(duì)于自定義鍵盤無(wú)法像系統(tǒng)鍵盤那樣使用Send Keys進(jìn)行輸入,于是接下來(lái)想到的是把鍵盤當(dāng)做普通控件處理,直接點(diǎn)擊進(jìn)行輸入,以下面app界面為例



在文本框中輸入股票代碼“600004”

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

        # 點(diǎn)擊鍵盤輸入股票代碼“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)

終端報(bào)錯(cuò)

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關(guān)鍵日志

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 {}

問(wèn)題原因?

解決方法:不能直接tap元素,只能tap對(duì)應(yīng)的坐標(biāo)才會(huì)有效,所以選擇封裝一個(gè)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(
            "http://UIAApplication[1]/UIAWindow[1]/UIAScrollView[1]/UIAScrollView[1]/UIATextField[1]").click()
        # sleep(2)
        # self.driver.hx_tap_element_with_name_sequence(('全倉(cāng)', '1',))
        self.driver.hx_tap_element_with_name_sequence('600000')
        self.driver.find_element_by_xpath(
            "http://UIAApplication[1]/UIAWindow[1]/UIAScrollView[1]/UIAScrollView[1]/UIATextField[3]").click()
        sleep(2)
        self.driver.hx_tap_element_with_name_args('全倉(cāng)', '半倉(cāng)', '2/3倉(cāng)')

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 1、窗體 1、常用屬性 (1)Name屬性:用來(lái)獲取或設(shè)置窗體的名稱,在應(yīng)用程序中可通過(guò)Name屬性來(lái)引用窗體。 ...
    Moment__格調(diào)閱讀 4,795評(píng)論 0 11
  • 1.contexts contexts(self): Returns the contexts within th...
    七月尾巴_葵花閱讀 2,291評(píng)論 0 10
  • ¥開啟¥ 【iAPP實(shí)現(xiàn)進(jìn)入界面執(zhí)行逐一顯】 〖2017-08-25 15:22:14〗 《//首先開一個(gè)線程,因...
    小菜c閱讀 7,363評(píng)論 0 17
  • 我的驕傲,就在今天毀在了我的手里,我的成績(jī)就這么跨下去了,我的內(nèi)心是痛苦的。我那么努力,為什么就換了這個(gè)結(jié)果。愿賭服輸。
    可可巧沁閱讀 336評(píng)論 0 0
  • 粉紅色的顏料一點(diǎn)點(diǎn)地在紙上綻放, 慢慢的,展露出她的色彩美, 最后,她現(xiàn)出櫻花色的光芒。 春天其實(shí)離我們并不遠(yuǎn),櫻...
    素淺暮染閱讀 280評(píng)論 0 3

友情鏈接更多精彩內(nèi)容