Appium python 版本的 webdriver 在 Android 平台下点击事件无效,求指导~
基本信息环境:Android+python+appium+w8
版本:python-2.7、appium-1.4.0.0
实现功能
Android内的chrome浏览器打开被测web,实现点击[注册]BTN的功能,并进行跳转
代码
#coding=utf-8
from appium import webdriver
import time
def ptest():
desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '4.4.4'
desired_caps['deviceName'] = 'MI 3'
desired_caps['browserName'] = 'chrome'
desired_caps['noReset'] = 'true'
dr = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
url = ''
dr.get(url)
time.sleep(5)
button = dr.find_element_by_class_name('register')
button.click()
dr.quit()
return问题
python版本的webdriver在Android平台下点击事件失效
执行button.click()后,请求成功,但是appium返回的值始终value都是空
页面按钮是js实现的,改用下面这句也不行,但按钮绝对找到了,执行js的浅出效果可以生效了,就是不能click跳转页面
dr.execute_script('$(arguments).click()', button)LOG
担心丢失信息,我把所有log都贴了上来,其中标黑的部分返回值为空
Checking if an update is available
Update available to new version 1.4.13.1
Starting Node Server
warn: Appium support for versions of node < 0.12 has been deprecated and will be removed in a future version. Please upgrade!
info: Welcome to Appium v1.4.0 (REV 8f63e2f91ef7907aed8bda763f4e5ca08e86970a)
info: Appium REST http interface listener started on 127.0.0.1:4723
info: Non-default server args: {"address":"127.0.0.1","logNoColors":true,"platformName":"Android","platformVersion":"18","automationName":"Appium"}
info: Console LogLevel: debug
info: --> POST /wd/hub/session {"desiredCapabilities":{"platformVersion":"4.4.4","deviceName":"MI 3","browserName":"chrome","platformName":"Android","noReset":"true"}}
info: Client User-Agent string: Python-urllib/2.7
warn: Converting cap noReset from string to boolean. This might cause unexpected behavior.
info: Set mode: Proxying straight through to Chromedriver
info: Looks like we want chrome on android
info: Creating new appium session b4e85ce9-2c2a-44cf-8a92-f64d10246acf
info: Checking whether adb is present
info: Using adb from C:\Program Files\android-sdk-windows\platform-tools\adb.exe
info: Using fast reset? false
info: Preparing device for session
info: Not checking whether app is present since we are assuming it's already on the device
info: Retrieving device
info: Trying to find a connected android device
info: Getting connected devices...
info: executing cmd: "C:\Program Files\android-sdk-windows\platform-tools\adb.exe" devices
info: 1 device(s) connected
info: Found device 253254d5
info: Setting device id to 253254d5
info: Waiting for device to be ready and to respond to shell commands (timeout = 5)
info: executing cmd: "C:\Program Files\android-sdk-windows\platform-tools\adb.exe" -s 253254d5 wait-for-device
info: executing cmd: "C:\Program Files\android-sdk-windows\platform-tools\adb.exe" -s 253254d5 shell "echo 'ready'"
info: Starting logcat capture
info: Set chromedriver binary as: C:\Program Files (x86)\Appium\node_modules\appium\build\chromedriver\windows\chromedriver.exe
info: Set chromedriver binary as: C:\Program Files (x86)\Appium\node_modules\appium\build\chromedriver\windows\chromedriver.exe
info: Pushing unlock helper app to device...
info: executing cmd: "C:\Program Files\android-sdk-windows\platform-tools\adb.exe" -s 253254d5 install "C:\Program Files (x86)\Appium\node_modules\appium\build\unlock_apk\unlock_apk-debug.apk"
info: executing cmd: "C:\Program Files\android-sdk-windows\platform-tools\adb.exe" -s 253254d5 shell "dumpsys window"
info: Unlocking screen
info: Screen is locked, trying to unlock
info: Getting device API level
info: executing cmd: "C:\Program Files\android-sdk-windows\platform-tools\adb.exe" -s 253254d5 shell "getprop ro.build.version.sdk"
info: Device is at API Level 19
info: executing cmd: "C:\Program Files\android-sdk-windows\platform-tools\adb.exe" -s 253254d5 shell "am start -S -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -f 0x10200000 -n io.appium.unlock/.Unlock"
info: executing cmd: "C:\Program Files\android-sdk-windows\platform-tools\adb.exe" -s 253254d5 shell "dumpsys window"
info: Screen is locked, trying to unlock
info: Getting device API level
info: executing cmd: "C:\Program Files\android-sdk-windows\platform-tools\adb.exe" -s 253254d5 shell "getprop ro.build.version.sdk"
info: Device is at API Level 19
info: executing cmd: "C:\Program Files\android-sdk-windows\platform-tools\adb.exe" -s 253254d5 shell "am start -S -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -f 0x10200000 -n io.appium.unlock/.Unlock"
info: executing cmd: "C:\Program Files\android-sdk-windows\platform-tools\adb.exe" -s 253254d5 shell "dumpsys window"
info: Screen is unlocked, continuing
info: Forwarding system:4724 to device:4724
info: executing cmd: "C:\Program Files\android-sdk-windows\platform-tools\adb.exe" -s 253254d5 forward tcp:4724 tcp:4724
info: Pushing appium bootstrap to device...
info: executing cmd: "C:\Program Files\android-sdk-windows\platform-tools\adb.exe" -s 253254d5 push "C:\Program Files (x86)\Appium\node_modules\appium\build\android_bootstrap\AppiumBootstrap.jar" /data/local/tmp/
info: Starting App
info: Attempting to kill all 'uiautomator' processes
info: Getting all processes with 'uiautomator'
info: executing cmd: "C:\Program Files\android-sdk-windows\platform-tools\adb.exe" -s 253254d5 shell "ps 'uiautomator'"
info: No matching processes found
info: Running bootstrap
info: spawning: C:\Program Files\android-sdk-windows\platform-tools\adb.exe -s 253254d5 shell uiautomator runtest AppiumBootstrap.jar -c io.appium.android.bootstrap.Bootstrap -e pkg com.android.chrome -e disableAndroidWatchers false
info: INSTRUMENTATION_STATUS: numtests=1
info: INSTRUMENTATION_STATUS: stream=
info: io.appium.android.bootstrap.Bootstrap:
info: INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
info: INSTRUMENTATION_STATUS: test=testRunServer
info: INSTRUMENTATION_STATUS: class=io.appium.android.bootstrap.Bootstrap
info: INSTRUMENTATION_STATUS: current=1
info: INSTRUMENTATION_STATUS_CODE: 1
info: Socket opened on port 4724
info: Appium Socket Server Ready
info: Loading json...
info: Pushing command to appium work queue: ["getDataDir",{}]
info: json loading complete.
info: Registered crash watchers.
info: Client connected
info: Got data from client: {"cmd":"action","action":"getDataDir","params":{}}
info: Got command of type ACTION
info: Got command action: getDataDir
info: dataDir set to: /data/local/tmp
info: Killing any old chromedrivers, running: FOR /F "usebackq tokens=5" %a in (netstat -nao ^| findstr /R /C:"9515 ") do (FOR /F "usebackq" %b in (TASKLIST /FI "PID eq %a" ^| findstr /I chromedriver.exe) do (IF NOT %b=="" TASKKILL /F /PID %a))
info: Returning result: {"value":"\/data\/local\/tmp","status":0}
info: No old chromedrivers seemed to exist
info: Spawning chromedriver with: C:\Program Files (x86)\Appium\node_modules\appium\build\chromedriver\windows\chromedriver.exe --url-base=wd/hub --port=9515
info: Starting ChromeDriver 2.15.322448 (52179c1b310fec1797c81ea9a20326839860b7d3) on port 9515
Only local connections are allowed.
info: Proxying to with no body
info: Got response with status 200: {"sessionId":"","status":0,"value":{"build":{"version":"alpha"},"os":{"arch":"x86_64","name":"Windows NT","version":"6.3"}}}
info: Proxying to with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.android.chrome","androidDeviceSerial":"253254d5"}}}
info: Got response with status 200: {"sessionId":"de7dd879fcd4c51ea8b9653da996b15d","status":0,"value":{"acceptSslCerts":true,"applicationCacheEnabled":false,"browserConnectionEnabled":false,"browserName":"chrome","chrome":{},"cssSelect...
info: Overriding session id with "de7dd879fcd4c51ea8b9653da996b15d"
info: Device launched! Ready for commands
info: Setting command timeout to the default of 60 secs
info: Appium session started with sessionId de7dd879fcd4c51ea8b9653da996b15d
info: <-- POST /wd/hub/session 303 29651.625 ms - 70
info: --> GET /wd/hub/session/de7dd879fcd4c51ea8b9653da996b15d {}
info: Proxying to with body: {}
info: Got response with status 200: {"sessionId":"de7dd879fcd4c51ea8b9653da996b15d","status":0,"value":{"acceptSslCerts":true,"applicationCacheEnabled":false,"browserConnectionEnabled":false,"browserName":"chrome","chrome":{},"cssSelect...
info: <-- GET /wd/hub/session/de7dd879fcd4c51ea8b9653da996b15d 200 9.757 ms - 506
info: --> POST /wd/hub/session/de7dd879fcd4c51ea8b9653da996b15d/url {"url":"http://as-stage.wecash.net/wap_v4,sessionId:de7dd879fcd4c51ea8b9653da996b15d"}
info: Proxying to with body: {"url":"http://as-stage.wecash.net/wap_v4,sessionId:de7dd879fcd4c51ea8b9653da996b15d"}
info: Got response with status 200: {"sessionId":"de7dd879fcd4c51ea8b9653da996b15d","status":0,"value":null}
info: <-- POST /wd/hub/session/de7dd879fcd4c51ea8b9653da996b15d/url 200 2155.140 ms - 72
info: --> POST /wd/hub/session/de7dd879fcd4c51ea8b9653da996b15d/element {"using":"class name","sessionId":"de7dd879fcd4c51ea8b9653da996b15d","value":"register"}
info: Proxying to with body: {"using":"class name","sessionId":"de7dd879fcd4c51ea8b9653da996b15d","value":"register"}
info: Got response with status 200: {"sessionId":"de7dd879fcd4c51ea8b9653da996b15d","status":0,"value":{"ELEMENT":"0.30392428231425583-1"}}
info: <-- POST /wd/hub/session/de7dd879fcd4c51ea8b9653da996b15d/element 200 125.408 ms - 103
info: --> POST /wd/hub/session/de7dd879fcd4c51ea8b9653da996b15d/element/0.30392428231425583-1/click {"sessionId":"de7dd879fcd4c51ea8b9653da996b15d","id":"0.30392428231425583-1"}
info: Proxying to with body: {"sessionId":"de7dd879fcd4c51ea8b9653da996b15d","id":"0.30392428231425583-1"}
info: Got response with status 200: {"sessionId":"de7dd879fcd4c51ea8b9653da996b15d","status":0,"value":null}
info: <-- POST /wd/hub/session/de7dd879fcd4c51ea8b9653da996b15d/element/0.30392428231425583-1/click 200 229.823 ms - 72
info: --> DELETE /wd/hub/session/de7dd879fcd4c51ea8b9653da996b15d {}
info: Shutting down appium session
info: Proxying to with no body
info: Got response with status 200: {"sessionId":"de7dd879fcd4c51ea8b9653da996b15d","status":0,"**value":null}
info: Got data from client: {"cmd":"shutdown"}
info: Got command of type SHUTDOWN
info: Sent shutdown command, waiting for UiAutomator to stop...
info: Returning result: {"value":"OK, shutting down","status":0}
info: Closed client connection
info: INSTRUMENTATION_STATUS: numtests=1
info: INSTRUMENTATION_STATUS: stream=.
info: INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
info: INSTRUMENTATION_STATUS: test=testRunServer
info: INSTRUMENTATION_STATUS: class=io.appium.android.bootstrap.Bootstrap
info: INSTRUMENTATION_STATUS: current=1
info: INSTRUMENTATION_STATUS_CODE: 0
info: INSTRUMENTATION_STATUS: stream=
info: Test results for WatcherResultPrinter=.
info: Time: 16.286
info: OK (1 test)
info: INSTRUMENTATION_STATUS_CODE: -1
info: UiAutomator shut down normally
info: executing cmd: "C:\Program Files\android-sdk-windows\platform-tools\adb.exe" -s 253254d5 shell "am force-stop com.android.chrome"
info: Stopping logcat capture
info: Logcat terminated with code null, signal SIGTERM
info: Cleaning up appium session
info: Responding to client with success: {"status":0,"value":null,"sessionId":"de7dd879fcd4c51ea8b9653da996b15d"}
info: <-- DELETE /wd/hub/session/de7dd879fcd4c51ea8b9653da996b15d 200 1590.341 ms - 72 {"status":0,"value":null,"sessionId":"de7dd879fcd4c51ea8b9653da996b15d"}
Killed Node Server.
Node Server Process Ended请各位大神指点一二,这个问题困扰了很久了,多谢(>_<)
1.没有排版
2.错误日志没有给出
首先你的页面是这样的:
(function () {
var self = null
var welcome = {
init: function () {
self = this
self.bind()
},
bind: function () {
$(document)
.on('tap', '#register', function () {
location.assign('register_first_step.html?v=' + new Date().getTime())
})
.on('tap', '#login', function () {
location.assign('login.html?v=' + new Date().getTime())
})
}
}
welcome.init()
})()
也就是说 click 估计压根不能触发你的 tap 事件,所以肯定不能跳转。 试试看执行下面的脚本,我测试是可以的。function triggerEventOnPage(selector, eventName, memo) {
//casper.evaluate(function(selector, eventName, memo){
var event;
var element = document.querySelector(selector);
event = document.createEvent("Event");
event.initEvent(eventName, true, true);
event.memo = memo || { };
element.dispatchEvent(event);
//}, selector, eventName, memo);
//wait();
}
triggerEventOnPage("#register", "tap");
草帽路飞UU 发表于 2017-11-23 12:22
试试看执行下面的脚本,我测试是可以的。
谢谢了,尝试了下确实可以。
页:
[1]