appium_iOS使用自定义键盘输入问题

对于自定义键盘无法像系统键盘那样使用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 {}

问题原因?

解决方法:不能直接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仓')

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 199,519评论 5 468
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 83,842评论 2 376
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 146,544评论 0 330
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 53,742评论 1 271
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 62,646评论 5 359
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,027评论 1 275
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,513评论 3 390
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,169评论 0 254
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,324评论 1 294
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,268评论 2 317
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,299评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,996评论 3 315
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,591评论 3 303
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,667评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,911评论 1 255
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,288评论 2 345
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 41,871评论 2 341

推荐阅读更多精彩内容