import os
import unittest
from appium import webdriver
from time import sleep
PATH = lambda p: os.path.abspath(
os.path.join(os.path.dirname(file), p)
)
desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '4.2.2'
desired_caps['deviceName'] = 'Android Emulator'
desired_caps['app'] = PATH(
'D:/Python/appium/ContactManager.apk'
)
desired_caps['appPackage'] = 'com.example.android.contactmanager'
desired_caps['appActivity'] = '.ContactManager'
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
driver.find_element_by_name("Add Contact")
els = driver.find_elements_by_android_uiautomator('new UiSelector().clickable(true)')
print els
driver.quit()
===code 部分
info: Welcome to Appium v1.0.0 (REV f0a00fab2335fa88cb355ab4dc43a9cd3f3236c0)
info: Appium REST http interface listener started on 127.0.0.1:4723
info: socket.io started
info: Non-default server args: {"udid":"HC3BGW9E0305","address":"127.0.0.1","log":"D:\Python\appium\log\2014-05-03.log"}
debug: Appium request initiated at /wd/hub/session
debug: Request received with params: {"sessionId":null,"desiredCapabilities":{"deviceName":"Android Emulator","app":"D:\Python\appium\ContactManager.apk","platformVersion":"4.2.2","appPackage":"com.example.android.contactmanager","platformName":"Android","appActivity":".ContactManager"}}
info: Using local app from desired caps: D:\Python\appium\ContactManager.apk
info: Creating new appium session 96c07e38-8897-4abb-8ff8-d6b0ecb5b552
info: Starting android appium
debug: Using fast reset? true
info: Preparing device for session
info: Checking whether app is actually present
info: Checking whether adb is present
info: [ADB] Using adb from D:\Python\eclipse\sdk\platform-tools\adb.exe
info: Trying to find a connected android device
info: [ADB] Getting connected devices...
debug: executing: "D:\Python\eclipse\sdk\platform-tools\adb.exe" devices
info: [ADB] 1 device(s) connected
info: Setting device id to HC3BGW9E0305
info: [ADB] Waiting for device to be ready and to respond to shell commands (timeout = 5)
debug: executing: "D:\Python\eclipse\sdk\platform-tools\adb.exe" -s HC3BGW9E0305 wait-for-device
debug: executing: "D:\Python\eclipse\sdk\platform-tools\adb.exe" -s HC3BGW9E0305 shell "echo 'ready'"
info: Starting logcat capture
info: Getting device API level
debug: executing: "D:\Python\eclipse\sdk\platform-tools\adb.exe" -s HC3BGW9E0305 shell "getprop ro.build.version.sdk"
info: Device is at API Level 17
debug: java -jar "C:\Users\Administrator\AppData\Roaming\npm\node_modules\appium\lib\devices\android\helpers\strings_from_apk.jar" "D:\Python\appium\ContactManager.apk" "C:\Windows\Temp\com.example.android.contactmanager"
debug: executing: "D:\Python\eclipse\sdk\platform-tools\adb.exe" -s HC3BGW9E0305 push "C:\Windows\Temp\com.example.android.contactmanager\strings.json" /data/local/tmp
info: Checking whether aapt is present
info: [ADB] Using aapt from D:\Python\eclipse\sdk\build-tools\17.0.0\aapt.exe
debug: processFromManifest: "D:\Python\eclipse\sdk\build-tools\17.0.0\aapt.exe" dump xmltree "D:\Python\appium\ContactManager.apk" AndroidManifest.xml
debug: Set app process to: .contactmanager
debug: Not uninstalling app since server not started with --full-reset
debug: Checking app cert for D:\Python\appium\ContactManager.apk: java -jar "C:\Users\Administrator\AppData\Roaming\npm\node_modules\appium\lib\devices\android\helpers\verify.jar" "D:\Python\appium\ContactManager.apk"
debug: App already signed.
info: Zip-aligning D:\Python\appium\ContactManager.apk
info: Checking whether zipalign is present
info: [ADB] Using zipalign from D:\Python\eclipse\sdk\tools\zipalign.exe
debug: zipAlignApk: "D:\Python\eclipse\sdk\tools\zipalign.exe" -f 4 "D:\Python\appium\ContactManager.apk" "E:\Temp\appium11443-5860-16vs21k.tmp"
info: MD5 for app is b2d2916bb5388e1dc281ec3e71ef1234
debug: executing: "D:\Python\eclipse\sdk\platform-tools\adb.exe" -s HC3BGW9E0305 shell "ls /data/local/tmp/b2d2916bb5388e1dc281ec3e71ef1234.apk"
debug: Getting install status for com.example.android.contactmanager
debug: executing: "D:\Python\eclipse\sdk\platform-tools\adb.exe" -s HC3BGW9E0305 shell "pm list packages -3 com.example.android.contactmanager"
info: [ADB] App is installed
info: Running fast reset (stop and clear)
debug: executing: "D:\Python\eclipse\sdk\platform-tools\adb.exe" -s HC3BGW9E0305 shell "am force-stop com.example.android.contactmanager"
debug: executing: "D:\Python\eclipse\sdk\platform-tools\adb.exe" -s HC3BGW9E0305 shell "pm clear com.example.android.contactmanager"
info: [ADB] Forwarding system:4724 to device:4724
debug: executing: "D:\Python\eclipse\sdk\platform-tools\adb.exe" -s HC3BGW9E0305 forward tcp:4724 tcp:4724
debug: Pushing appium bootstrap to device...
debug: executing: "D:\Python\eclipse\sdk\platform-tools\adb.exe" -s HC3BGW9E0305 push "C:\Users\Administrator\AppData\Roaming\npm\node_modules\appium\build\android_bootstrap\AppiumBootstrap.jar" /data/local/tmp/
debug: Pushing unlock helper app to device...
debug: executing: "D:\Python\eclipse\sdk\platform-tools\adb.exe" -s HC3BGW9E0305 install "C:\Users\Administrator\AppData\Roaming\npm\node_modules\appium\build\unlock_apk\unlock_apk-debug.apk"
info: Attempting to kill all 'uiautomator' processes
info: Getting all processes with 'uiautomator'
debug: executing: "D:\Python\eclipse\sdk\platform-tools\adb.exe" -s HC3BGW9E0305 shell "ps 'uiautomator'"
info: No matching processes found
info: Running bootstrap
debug: spawning: D:\Python\eclipse\sdk\platform-tools\adb.exe -s HC3BGW9E0305 shell uiautomator runtest AppiumBootstrap.jar -c io.appium.android.bootstrap.Bootstrap
info: [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: current=1
info: [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
info: [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: class=io.appium.android.bootstrap.Bootstrap
info: [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=
info: [UIAUTOMATOR STDOUT] io.appium.android.bootstrap.Bootstrap:
info: [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: numtests=1
info: [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: test=testRunServer
info: [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: 1
info: [BOOTSTRAP] [info] Socket opened on port 4724
info: [BOOTSTRAP] [info] Appium Socket Server Ready
info: [BOOTSTRAP] [info] Loading json...
debug: Waking up device if it's not alive
info: Pushing command to appium work queue: ["wake",{}]
info: [BOOTSTRAP] [info] json loading complete.
info: [BOOTSTRAP] [info] Registered crash watchers.
info: [BOOTSTRAP] [info] Client connected
info: [BOOTSTRAP] [info] Got data from client: {"cmd":"action","action":"wake","params":{}}
info: [BOOTSTRAP] [info] Got command of type ACTION
info: [BOOTSTRAP] [debug] Got command action: wake
debug: executing: "D:\Python\eclipse\sdk\platform-tools\adb.exe" -s HC3BGW9E0305 shell "dumpsys window"
info: [BOOTSTRAP] [info] Returning result: {"value":true,"status":0}
info: Writing dumpsys output to C:\Users\Administrator\AppData\Roaming\npm\node_modules\appium.dumpsys.log
debug: Screen already unlocked, continuing.
info: Pushing command to appium work queue: ["getDataDir",{}]
info: [BOOTSTRAP] [info] Got data from client: {"cmd":"action","action":"getDataDir","params":{}}
debug: dataDir set to: /data/local/tmp
debug: executing: "D:\Python\eclipse\sdk\platform-tools\adb.exe" -s HC3BGW9E0305 shell "am start -S -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -f 0x10200000 -n com.example.android.contactmanager/.ContactManager"
info: [BOOTSTRAP] [info] Got command of type ACTION
info: [BOOTSTRAP] [debug] Got command action: getDataDir
info: [BOOTSTRAP] [info] Returning result: {"value":"\/data\/local\/tmp","status":0}
info: Waiting for activity to be focused
info: Getting focused package and activity
debug: executing: "D:\Python\eclipse\sdk\platform-tools\adb.exe" -s HC3BGW9E0305 shell "dumpsys window windows"
info: Device launched! Ready for commands
info: Setting command timeout to the default of 60 secs
info: Appium session started with sessionId 96c07e38-8897-4abb-8ff8-d6b0ecb5b552
debug: 127.0.0.1 - - "POST /wd/hub/session HTTP/1.1" - 9 "-" "Python-urllib/2.7"
debug: Appium request initiated at /wd/hub/session/96c07e38-8897-4abb-8ff8-d6b0ecb5b552
debug: Request received with params: {}
info: Responding to client with success: {"status":0,"value":{"platform":"LINUX","browserName":"Android","platformVersion":"4.2.2","webStorageEnabled":false,"takesScreenshot":true,"javascriptEnabled":true,"databaseEnabled":false,"warnings":{},"desired":{"deviceName":"Android Emulator","app":"D:\Python\appium\ContactManager.apk","platformVersion":"4.2.2","appPackage":"com.example.android.contactmanager","platformName":"Android","appActivity":".ContactManager"},"deviceName":"Android Emulator","app":"D:\Python\appium\ContactManager.apk","appPackage":"com.example.android.contactmanager","platformName":"Android","appActivity":".ContactManager"},"sessionId":"96c07e38-8897-4abb-8ff8-d6b0ecb5b552"}
debug: 127.0.0.1 - - "GET /wd/hub/session/96c07e38-8897-4abb-8ff8-d6b0ecb5b552 HTTP/1.1" - 817 "-" "Python-urllib/2.7"
debug: Appium request initiated at /wd/hub/session/96c07e38-8897-4abb-8ff8-d6b0ecb5b552/element
debug: Request received with params: {"using":"name","sessionId":"96c07e38-8897-4abb-8ff8-d6b0ecb5b552","value":"Add Contact"}
warn: [DEPRECATED] The "name" Locator strategy has been deprecated and will be removed. Please use the "accessibility id" Locator strategy instead.
info: Pushing command to appium work queue: ["find",{"strategy":"name","selector":"Add Contact","context":"","multiple":false}]
info: [BOOTSTRAP] [info] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"name","selector":"Add Contact","context":"","multiple":false}}
info: [BOOTSTRAP] [info] Got command of type ACTION
info: [BOOTSTRAP] [debug] Got command action: find
info: [BOOTSTRAP] [debug] Finding Add Contact using NAME with the contextId:
info: [BOOTSTRAP] [info] Returning result: {"value":{"ELEMENT":"1"},"status":0}
info: Responding to client with success: {"status":0,"value":{"ELEMENT":"1"},"sessionId":"96c07e38-8897-4abb-8ff8-d6b0ecb5b552"}
debug: 127.0.0.1 - - "POST /wd/hub/session/96c07e38-8897-4abb-8ff8-d6b0ecb5b552/element HTTP/1.1" - 109 "-" "Python-urllib/2.7"
debug: Appium request initiated at /wd/hub/session/96c07e38-8897-4abb-8ff8-d6b0ecb5b552/element/1/click
debug: Request received with params: {"sessionId":"96c07e38-8897-4abb-8ff8-d6b0ecb5b552","id":"1"}
info: Pushing command to appium work queue: ["element:click",{"elementId":"1"}]
info: [BOOTSTRAP] [info] Got data from client: {"cmd":"action","action":"element:click","params":{"elementId":"1"}}
info: [BOOTSTRAP] [info] Got command of type ACTION
info: [BOOTSTRAP] [debug] Got command action: click
info: [BOOTSTRAP] [info] Returning result: {"value":true,"status":0}
info: Responding to client with success: {"status":0,"value":true,"sessionId":"96c07e38-8897-4abb-8ff8-d6b0ecb5b552"}
debug: 127.0.0.1 - - "POST /wd/hub/session/96c07e38-8897-4abb-8ff8-d6b0ecb5b552/element/1/click HTTP/1.1" - 89 "-" "Python-urllib/2.7"
debug: Appium request initiated at /wd/hub/session/96c07e38-8897-4abb-8ff8-d6b0ecb5b552/elements
debug: Request received with params: {"using":"-android uiautomator","sessionId":"96c07e38-8897-4abb-8ff8-d6b0ecb5b552","value":"new UiSelector().clickable(true)"}
info: Pushing command to appium work queue: ["find",{"strategy":"-android uiautomator","selector":"new UiSelector().clickable(true)","context":"","multiple":true}]
info: [BOOTSTRAP] [info] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"-android uiautomator","selector":"new UiSelector().clickable(true)","context":"","multiple":true}}
info: [BOOTSTRAP] [info] Got command of type ACTION
info: [BOOTSTRAP] [debug] Got command action: find
info: [BOOTSTRAP] [debug] Finding new UiSelector().clickable(true) using ANDROID_UIAUTOMATOR with the contextId:
info: [BOOTSTRAP] [info] Element[] is null: (0)
info: [BOOTSTRAP] [info] Element[] is null: (1)
info: [BOOTSTRAP] [info] Element[] is null: (2)
info: [BOOTSTRAP] [info] Element[] is null: (3)
info: [BOOTSTRAP] [info] Element[] is null: (4)
info: [BOOTSTRAP] [info] Element[] is null: (5)
info: [BOOTSTRAP] [info] Element[] is null: (6)
info: [BOOTSTRAP] [info] Element[] is null: (7)
info: [BOOTSTRAP] [info] Element[] is null: (8)
info: [BOOTSTRAP] [info] Element[] is null: (9)
info: [BOOTSTRAP] [info] Element[] is null: (10)
info: [BOOTSTRAP] [info] Element[] is null: (11)
info: [BOOTSTRAP] [info] Element[] is null: (12)
info: [BOOTSTRAP] [info] Element[] is null: (13)
info: [BOOTSTRAP] [info] Element[] is null: (14)
info: [BOOTSTRAP] [info] Element[] is null: (15)
info: [BOOTSTRAP] [info] Element[] is null: (16)
info: [BOOTSTRAP] [info] Element[] is null: (17)
info: [BOOTSTRAP] [info] Element[] is null: (18)
info: [BOOTSTRAP] [info] Element[] is null: (19)
info: [BOOTSTRAP] [info] Element[] is null: (20)
info: [BOOTSTRAP] [info] Element[] is null: (21)
info: [BOOTSTRAP] [info] Element[] is null: (22)
info: [BOOTSTRAP] [info] Element[] is null: (23)
info: [BOOTSTRAP] [info] Element[] is null: (24)
info: [BOOTSTRAP] [info] Element[] is null: (25)
info: [BOOTSTRAP] [info] Element[] is null: (26)
info: [BOOTSTRAP] [info] Element[] is null: (27)
info: [BOOTSTRAP] [info] Element[] is null: (28)
info: [BOOTSTRAP] [info] Element[] is null: (29)
info: [BOOTSTRAP] [info] Element[] is null: (30)
info: [BOOTSTRAP] [info] Element[] is null: (31)
info: [BOOTSTRAP] [info] Element[] is null: (32)
info: [BOOTSTRAP] [info] Element[] is null: (33)
info: [BOOTSTRAP] [info] Element[] is null: (34)
info: [BOOTSTRAP] [info] Element[] is null: (35)
info: [BOOTSTRAP] [info] Element[] is null: (36)
info: [BOOTSTRAP] [info] Element[] is null: (37)
info: [BOOTSTRAP] [info] Element[] is null: (38)
info: [BOOTSTRAP] [info] Element[] is null: (39)
info: [BOOTSTRAP] [info] Element[] is null: (40)
info: [BOOTSTRAP] [info] Element[] is null: (41)
info: [BOOTSTRAP] [info] Element[] is null: (42)
===日志部分
求助为什么后面都是 element[] is null
这个方法找不到界面上可点击的目标控件么