问题

测试 iOS 时, 使用 xpath 查找控件, xpath 中使用属性定位不到控件.
Android 系统测试时, 可以使用.
比如:

driver.element_by_xpath("//XCUIElementTypeButton[@name='好价']")

相关 log

macaca server --verbose
>> responseHandler.js:11:12 [master] pid:47529 Recieve HTTP Request from Client: method: POST url: /wd/hub/session/594a667f-959a-48b9-96ef-feb5bf5e7481/element, jsonBody: {"using":"xpath","value":"//XCUIElementTypeButton[@name='好价']"}
>> proxy.js:56:14 [master] pid:47529 Proxy: /wd/hub/session/594a667f-959a-48b9-96ef-feb5bf5e7481/element:POST to http://172.16.24.87:8900/session/DA7E2B07-D47A-4C63-85F0-79D3EDBFC76C/element:POST with body: {"using":"xpath","value":"//XCUIElementTypeButton[@name='好价']"}
>> proxy.js:84:20 [master] pid:47529 Got response with status 200: {"value":{"using":"xpath","value":"//XCUIElementTypeButton[@name='好价']","description":"unable to find an element"},"sessionId":"594a667f-959a-48b9-96ef-feb5bf5e7481","status":7}
>> session.js:107:14 [master] pid:47529 Send HTTP Respone to Client: {"value":"{\"using\":\"xpath\",\"value\":\"//XCUIElementTypeButton[@name='好价']\",\"description\":\"unable to find an element\"}","sessionId":"594a667f-959a-48b9-96ef-feb5bf5e7481","status":7}
Python log
----> 1 driver.element_by_xpath("//XCUIElementTypeButton[@name='好价']")

/Users/smzdm/python_env/macaca/lib/python2.7/site-packages/macaca/util.pyc in find_element(self, value)
     75
     76         def find_element(self, value):
---> 77             return self.element(using.value, value)
     78
     79         find_element.__name__ = find_element_name

/Users/smzdm/python_env/macaca/lib/python2.7/site-packages/macaca/webdriver.pyc in element(self, using, value)
    812         return self._execute(Command.FIND_ELEMENT, {
    813             'using': using,
--> 814             'value': value
    815         })
    816

/Users/smzdm/python_env/macaca/lib/python2.7/site-packages/macaca/webdriver.pyc in _execute(self, command, data, unpack)
     66         res = self.remote_invoker.execute(command, data)
     67         ret = WebDriverResult.from_object(res)
---> 68         ret.raise_for_status()
     69         ret.value = self._unwrap_el(ret.value)
     70         if not unpack:

/Users/smzdm/python_env/macaca/lib/python2.7/site-packages/macaca/webdriverresult.pyc in raise_for_status(self)
     52             stacktrace = self.value.get('stacktrace', None)
     53
---> 54         raise WebDriverException(error, message, screen, stacktrace)

WebDriverException:
Error: WebDriverError.NO_SUCH_ELEMENT
Message: None

app-inspector 截图

系统环境

Mac OS: 10.12.1
wd: 0.1.5
Macaca: 1.1.21

➜  ~ macaca doctor

  macaca-doctor version: 1.0.28

  Node.js checklist:

  node env: /usr/local/bin/node
  node version: v5.0.0

  iOS checklist:

  Xcode is installed at: `/Applications/Xcode.app/Contents/Developer`
  Xcode Command Line Tools is ready, version: 2345.1.
  iproxy[usbmuxd] is installed at: `/usr/local/bin/iproxy`
  ios_webkit_debug_proxy is installed at: `/usr/local/bin/ios_webkit_debug_proxy`

  Android checklist:

  JAVA version is `1.8.0_20`
  JAVA_HOME is set to `/Library/Java/JavaVirtualMachines/jdk1.8.0_20.jdk/Contents/Home`
  ANDROID_HOME is set to `/Users/smzdm/Documents/01_Android/adt-bundle-mac-x86_64-20140702/sdk`
  Platforms is set to `/Users/smzdm/Documents/01_Android/adt-bundle-mac-x86_64-20140702/sdk/platforms/android-24`
  Android tools is set to `/Users/smzdm/Documents/01_Android/adt-bundle-mac-x86_64-20140702/sdk/tools/android`
  ADB tool is set to `/Users/smzdm/Documents/01_Android/adt-bundle-mac-x86_64-20140702/sdk/platform-tools/adb`

  Installed driver list:

  android: 1.1.15
  ios: 1.0.53


↙↙↙阅读原文可查看相关链接,并与作者交流