测试代码如下:

#coding=utf-8
from appium import webdriver
import time
'''
登陆
'''
desired_caps = {}
desired_caps['platformName'] = 'ios'
desired_caps['platformVersion'] = '8.4'
desired_caps['deviceName'] = 'iPhone Simulator'
desired_caps['app'] = ('/Users/yspan/Library/Developer/Xcode/DerivedData/eap-gnvyowbftuqxtxanwpnobrkvpmdy/Build/Products/Debug-iphonesimulator/eap.app')
desired_caps['bundleId'] = 'nanwang.csg.cn.iphone'
print("连接中...")
wd = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
print("连接完成!")
time.sleep(30)
wd.find_element_by_xpath("//UIAApplication[1]/UIAWindow[2]/UIATextField[1]/UIATextField[1]").send_keys("pan")
wd.find_element_by_xpath("//UIAApplication[1]/UIAWindow[2]/UIATextField[2]/UIATextField[1]").send_keys("15888888888")
wd.find_element_by_xpath("//UIAApplication[1]/UIAWindow[2]/UIATextField[3]/UIATextField[1]").send_keys("5555")
wd.find_element_by_name('登录').click()
print("success")
time.sleep(10)
wd.quit()

appium inspector 截图信息如下:

appium 日志如下:

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":24.125,"width":375,"height":642.1875},">":[{"UIAWindow":{"@":{"name":null,"label":null,"value":null,"dom":null,"enabled":true,

info: [debug] Pushing command to appium work queue: "au.getElementByIndexPath('/0/1/3/0')"

info: [debug] Sending command to instruments: au.getElementByIndexPath('/0/1/3/0')

info: [debug] [INST] 2016-02-22 06:40:51 +0000 Debug: Got new command 4 from instruments: au.getElementByIndexPath('/0/1/3/0')

info: [debug] [INST] 2016-02-22 06:40:51 +0000 Debug: evaluating au.getElementByIndexPath('/0/1/3/0')

info: [debug] [INST] 2016-02-22 06:40:51 +0000 Debug: evaluation finished
info: [debug] [INST] 2016-02-22 06:40:51 +0000 Debug: responding with:
info: [debug] [INST] 2016-02-22 06:40:51 +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: [debug] Socket data received (25 bytes)

info: [debug] Socket data being routed.
info: [debug] Got result from instruments: {"status":0,"value":""}
info: [debug] Condition unmet after 2430ms. Timing out.

info: [debug] Responding to client with error: {"status":7,"value":{"message":"An element could not be located on the page using the given search parameters.","origValue":""},"sessionId":"77424f61-8646-46bc-b9c9-4b3da01f385a"}
info: <-- POST /wd/hub/session/77424f61-8646-46bc-b9c9-4b3da01f385a/element 500 2434.032 ms - 179 

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

info: [debug] Responding to client with success: {"status":0,"value":{"build":{"version":"1.4.13","revision":"c75d8adcb66a75818a542fe1891a34260c21f76a"},"isShuttingDown":false},"sessionId":"77424f61-8646-46bc-b9c9-4b3da01f385a"}

info: <-- GET /wd/hub/status 200 2.789 ms - 179 {"status":0,"value":{"build":{"version":"1.4.13","revision":"c75d8adcb66a75818a542fe1891a34260c21f76a"},"isShuttingDown":false},"sessionId":"77424f61-8646-46bc-b9c9-4b3da01f385a"}

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

info: [debug] Responding to client with success: {"status":0,"value":{"build":{"version":"1.4.13","revision":"c75d8adcb66a75818a542fe1891a34260c21f76a"},"isShuttingDown":false},"sessionId":"77424f61-8646-46bc-b9c9-4b3da01f385a"}
info: <-- GET /wd/hub/status 200 1.779 ms - 179 {"status":0,"value":{"build":{"version":"1.4.13","revision":"c75d8adcb66a75818a542fe1891a34260c21f76a"},"isShuttingDown":false},"sessionId":"77424f61-8646-46bc-b9c9-4b3da01f385a"}

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

info: [debug] Responding to client with success: {"status":0,"value":{"build":{"version":"1.4.13","revision":"c75d8adcb66a75818a542fe1891a34260c21f76a"},"isShuttingDown":false},"sessionId":"77424f61-8646-46bc-b9c9-4b3da01f385a"}

info: <-- GET /wd/hub/status 200 1.148 ms - 179 {"status":0,"value":{"build":{"version":"1.4.13","revision":"c75d8adcb66a75818a542fe1891a34260c21f76a"},"isShuttingDown":false},"sessionId":"77424f61-8646-46bc-b9c9-4b3da01f385a"}

终端日志如下:

连接中...
连接完成!
Traceback (most recent call last):
  File "/Users/yspan/Documents/shili/Test_login.py", line 21, in <module>
    wd.find_element_by_xpath("//UIAApplication[1]/UIAWindow[2]/UIATextField[3]/UIATextField[1]").send_keys("5555")
  File "/Library/Python/2.7/site-packages/selenium-2.52.0-py2.7.egg/selenium/webdriver/remote/webdriver.py", line 258, in find_element_by_xpath
    return self.find_element(by=By.XPATH, value=xpath)
  File "/Library/Python/2.7/site-packages/selenium-2.52.0-py2.7.egg/selenium/webdriver/remote/webdriver.py", line 712, in find_element
    {'using': by, 'value': value})['value']
  File "/Library/Python/2.7/site-packages/selenium-2.52.0-py2.7.egg/selenium/webdriver/remote/webdriver.py", line 201, 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
selenium.common.exceptions.NoSuchElementException: Message: An element could not be located on the page using the given search parameters.

代码中,如果只是单独执行点击按钮的代码,是能正常执行的。文本输入内容部分的代码不能正常执行!


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