51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

手机号码,快捷登录

查看: 1956|回复: 6
打印 上一主题 下一主题

[Appium] Appium python 版本的 webdriver 在 Android 平台下点击事件无效,求指导~

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2017-11-23 12:00:12 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
基本信息
环境:Android+python+appium+w8
版本:python-2.7、appium-1.4.0.0
实现功能
Android内的chrome浏览器打开被测web,实现点击[注册]BTN的功能,并进行跳转
代码
  1. #coding=utf-8
  2. from appium import webdriver
  3. import time

  4. def ptest():
  5.     desired_caps = {}
  6.     desired_caps['platformName'] = 'Android'
  7.     desired_caps['platformVersion'] = '4.4.4'
  8.     desired_caps['deviceName'] = 'MI 3'
  9.     desired_caps['browserName'] = 'chrome'
  10.     desired_caps['noReset'] = 'true'
  11.     dr = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
  12.     url = ''
  13.     dr.get(url)
  14.     time.sleep(5)
  15.     button = dr.find_element_by_class_name('register')
  16.     button.click()
  17.     dr.quit()
  18.     return
复制代码
问题


python版本的webdriver在Android平台下点击事件失效
执行button.click()后,请求成功,但是appium返回的值始终value都是空
页面按钮是js实现的,改用下面这句也不行,但按钮绝对找到了,执行js的浅出效果可以生效了,就是不能click跳转页面
  1. dr.execute_script('$(arguments[0]).click()', button)
复制代码
LOG


担心丢失信息,我把所有log都贴了上来,其中标黑的部分返回值为空



分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏1
回复

使用道具 举报

该用户从未签到

2#
 楼主| 发表于 2017-11-23 12:00:54 | 只看该作者
  1. Checking if an update is available
  2. Update available to new version 1.4.13.1
  3. Starting Node Server
  4. warn: Appium support for versions of node < 0.12 has been deprecated and will be removed in a future version. Please upgrade!
  5. info: Welcome to Appium v1.4.0 (REV 8f63e2f91ef7907aed8bda763f4e5ca08e86970a)
  6. info: Appium REST http interface listener started on 127.0.0.1:4723
  7. info: [debug] Non-default server args: {"address":"127.0.0.1","logNoColors":true,"platformName":"Android","platformVersion":"18","automationName":"Appium"}
  8. info: Console LogLevel: debug
  9. info: --> POST /wd/hub/session {"desiredCapabilities":{"platformVersion":"4.4.4","deviceName":"MI 3","browserName":"chrome","platformName":"Android","noReset":"true"}}
  10. info: Client User-Agent string: Python-urllib/2.7
  11. warn: Converting cap noReset from string to boolean. This might cause unexpected behavior.
  12. info: Set mode: Proxying straight through to Chromedriver
  13. info: [debug] Looks like we want chrome on android
  14. info: [debug] Creating new appium session b4e85ce9-2c2a-44cf-8a92-f64d10246acf
  15. info: [debug] Checking whether adb is present
  16. info: [debug] Using adb from C:\Program Files\android-sdk-windows\platform-tools\adb.exe
  17. info: [debug] Using fast reset? false
  18. info: [debug] Preparing device for session
  19. info: [debug] Not checking whether app is present since we are assuming it's already on the device
  20. info: Retrieving device
  21. info: [debug] Trying to find a connected android device
  22. info: [debug] Getting connected devices...
  23. info: [debug] executing cmd: "C:\Program Files\android-sdk-windows\platform-tools\adb.exe" devices
  24. info: [debug] 1 device(s) connected
  25. info: Found device 253254d5
  26. info: [debug] Setting device id to 253254d5
  27. info: [debug] Waiting for device to be ready and to respond to shell commands (timeout = 5)
  28. info: [debug] executing cmd: "C:\Program Files\android-sdk-windows\platform-tools\adb.exe" -s 253254d5 wait-for-device
  29. info: [debug] executing cmd: "C:\Program Files\android-sdk-windows\platform-tools\adb.exe" -s 253254d5 shell "echo 'ready'"
  30. info: [debug] Starting logcat capture
  31. info: [debug] Set chromedriver binary as: C:\Program Files (x86)\Appium\node_modules\appium\build\chromedriver\windows\chromedriver.exe
  32. info: Set chromedriver binary as: C:\Program Files (x86)\Appium\node_modules\appium\build\chromedriver\windows\chromedriver.exe
  33. info: [debug] Pushing unlock helper app to device...
  34. info: [debug] 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"
  35. info: [debug] executing cmd: "C:\Program Files\android-sdk-windows\platform-tools\adb.exe" -s 253254d5 shell "dumpsys window"
  36. info: Unlocking screen
  37. info: [debug] Screen is locked, trying to unlock
  38. info: [debug] Getting device API level
  39. info: [debug] executing cmd: "C:\Program Files\android-sdk-windows\platform-tools\adb.exe" -s 253254d5 shell "getprop ro.build.version.sdk"
  40. info: [debug] Device is at API Level 19
  41. info: [debug] 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"
  42. info: [debug] executing cmd: "C:\Program Files\android-sdk-windows\platform-tools\adb.exe" -s 253254d5 shell "dumpsys window"
  43. info: [debug] Screen is locked, trying to unlock
  44. info: [debug] Getting device API level
  45. info: [debug] executing cmd: "C:\Program Files\android-sdk-windows\platform-tools\adb.exe" -s 253254d5 shell "getprop ro.build.version.sdk"
  46. info: [debug] Device is at API Level 19
  47. info: [debug] 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"
  48. info: [debug] executing cmd: "C:\Program Files\android-sdk-windows\platform-tools\adb.exe" -s 253254d5 shell "dumpsys window"
  49. info: [debug] Screen is unlocked, continuing
  50. info: [debug] Forwarding system:4724 to device:4724
  51. info: [debug] executing cmd: "C:\Program Files\android-sdk-windows\platform-tools\adb.exe" -s 253254d5 forward tcp:4724 tcp:4724
  52. info: [debug] Pushing appium bootstrap to device...
  53. info: [debug] 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/
  54. info: Starting App
  55. info: [debug] Attempting to kill all 'uiautomator' processes
  56. info: [debug] Getting all processes with 'uiautomator'
  57. info: [debug] executing cmd: "C:\Program Files\android-sdk-windows\platform-tools\adb.exe" -s 253254d5 shell "ps 'uiautomator'"
  58. info: [debug] No matching processes found
  59. info: [debug] Running bootstrap
  60. info: [debug] 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
复制代码

回复 支持 反对

使用道具 举报

该用户从未签到

3#
 楼主| 发表于 2017-11-23 12:01:34 | 只看该作者
  1. info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: numtests=1
  2. info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=
  3. info: [debug] [UIAUTOMATOR STDOUT] io.appium.android.bootstrap.Bootstrap:
  4. info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
  5. info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: test=testRunServer
  6. info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: class=io.appium.android.bootstrap.Bootstrap
  7. info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: current=1
  8. info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: 1
  9. info: [debug] [BOOTSTRAP] [debug] Socket opened on port 4724
  10. info: [debug] [BOOTSTRAP] [debug] Appium Socket Server Ready
  11. info: [debug] [BOOTSTRAP] [debug] Loading json...
  12. info: [debug] Pushing command to appium work queue: ["getDataDir",{}]
  13. info: [debug] [BOOTSTRAP] [debug] json loading complete.
  14. info: [debug] [BOOTSTRAP] [debug] Registered crash watchers.
  15. info: [debug] [BOOTSTRAP] [debug] Client connected
  16. info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"getDataDir","params":{}}
  17. info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
  18. info: [debug] [BOOTSTRAP] [debug] Got command action: getDataDir
  19. info: [debug] dataDir set to: /data/local/tmp
  20. 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))
  21. info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":"\/data\/local\/tmp","status":0}
  22. info: No old chromedrivers seemed to exist
  23. info: Spawning chromedriver with: C:\Program Files (x86)\Appium\node_modules\appium\build\chromedriver\windows\chromedriver.exe --url-base=wd/hub --port=9515
  24. info: [CHROMEDRIVER STDOUT] Starting ChromeDriver 2.15.322448 (52179c1b310fec1797c81ea9a20326839860b7d3) on port 9515
  25. Only local connections are allowed.
  26. info: Proxying [GET /status] to [GET http://127.0.0.1:9515/wd/hub/status] with no body
  27. info: Got response with status 200: {"sessionId":"","status":0,"value":{"build":{"version":"alpha"},"os":{"arch":"x86_64","name":"Windows NT","version":"6.3"}}}
  28. info: Proxying [POST /session] to [POST http://127.0.0.1:9515/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.android.chrome","androidDeviceSerial":"253254d5"}}}
  29. info: Got response with status 200: {"sessionId":"de7dd879fcd4c51ea8b9653da996b15d","status":0,"value":{"acceptSslCerts":true,"applicationCacheEnabled":false,"browserConnectionEnabled":false,"browserName":"chrome","chrome":{},"cssSelect...
  30. info: [debug] Overriding session id with "de7dd879fcd4c51ea8b9653da996b15d"
  31. info: [debug] Device launched! Ready for commands
  32. info: [debug] Setting command timeout to the default of 60 secs
  33. info: [debug] Appium session started with sessionId de7dd879fcd4c51ea8b9653da996b15d
  34. info: <-- POST /wd/hub/session 303 29651.625 ms - 70
  35. info: --> GET /wd/hub/session/de7dd879fcd4c51ea8b9653da996b15d {}
  36. info: Proxying [GET /wd/hub/session/de7dd879fcd4c51ea8b9653da996b15d] to [GET http://127.0.0.1:9515/wd/hub/session/de7dd879fcd4c51ea8b9653da996b15d] with body: {}
  37. info: Got response with status 200: {"sessionId":"de7dd879fcd4c51ea8b9653da996b15d","status":0,"value":{"acceptSslCerts":true,"applicationCacheEnabled":false,"browserConnectionEnabled":false,"browserName":"chrome","chrome":{},"cssSelect...
  38. info: <-- GET /wd/hub/session/de7dd879fcd4c51ea8b9653da996b15d 200 9.757 ms - 506
  39. info: --> POST /wd/hub/session/de7dd879fcd4c51ea8b9653da996b15d/url {"url":"http://as-stage.wecash.net/wap_v4,sessionId:de7dd879fcd4c51ea8b9653da996b15d"}
  40. info: Proxying [POST /wd/hub/session/de7dd879fcd4c51ea8b9653da996b15d/url] to [POST http://127.0.0.1:9515/wd/hub/session/de7dd879fcd4c51ea8b9653da996b15d/url] with body: {"url":"http://as-stage.wecash.net/wap_v4,sessionId:de7dd879fcd4c51ea8b9653da996b15d"}
  41. info: Got response with status 200: {"sessionId":"de7dd879fcd4c51ea8b9653da996b15d","status":0,"value":null}
  42. info: <-- POST /wd/hub/session/de7dd879fcd4c51ea8b9653da996b15d/url 200 2155.140 ms - 72
  43. info: --> POST /wd/hub/session/de7dd879fcd4c51ea8b9653da996b15d/element {"using":"class name","sessionId":"de7dd879fcd4c51ea8b9653da996b15d","value":"register"}
  44. info: Proxying [POST /wd/hub/session/de7dd879fcd4c51ea8b9653da996b15d/element] to [POST http://127.0.0.1:9515/wd/hub/session/de7dd879fcd4c51ea8b9653da996b15d/element] with body: {"using":"class name","sessionId":"de7dd879fcd4c51ea8b9653da996b15d","value":"register"}
  45. info: Got response with status 200: {"sessionId":"de7dd879fcd4c51ea8b9653da996b15d","status":0,"value":{"ELEMENT":"0.30392428231425583-1"}}
  46. info: <-- POST /wd/hub/session/de7dd879fcd4c51ea8b9653da996b15d/element 200 125.408 ms - 103
  47. info: --> POST /wd/hub/session/de7dd879fcd4c51ea8b9653da996b15d/element/0.30392428231425583-1/click {"sessionId":"de7dd879fcd4c51ea8b9653da996b15d","id":"0.30392428231425583-1"}
  48. info: Proxying [POST /wd/hub/session/de7dd879fcd4c51ea8b9653da996b15d/element/0.30392428231425583-1/click] to [POST http://127.0.0.1:9515/wd/hub/session/de7dd879fcd4c51ea8b9653da996b15d/element/0.30392428231425583-1/click] with body: {"sessionId":"de7dd879fcd4c51ea8b9653da996b15d","id":"0.30392428231425583-1"}
  49. info: Got response with status 200: {"sessionId":"de7dd879fcd4c51ea8b9653da996b15d","status":0,"value":null}
  50. info: <-- POST /wd/hub/session/de7dd879fcd4c51ea8b9653da996b15d/element/0.30392428231425583-1/click 200 229.823 ms - 72
  51. info: --> DELETE /wd/hub/session/de7dd879fcd4c51ea8b9653da996b15d {}
  52. info: Shutting down appium session
  53. info: Proxying [DELETE /] to [DELETE http://127.0.0.1:9515/wd/hub/session/de7dd879fcd4c51ea8b9653da996b15d] with no body
  54. info: Got response with status 200: {"sessionId":"de7dd879fcd4c51ea8b9653da996b15d","status":0,"**value":null}
  55. info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"shutdown"}
  56. info: [debug] [BOOTSTRAP] [debug] Got command of type SHUTDOWN
  57. info: [debug] Sent shutdown command, waiting for UiAutomator to stop...
  58. info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":"OK, shutting down","status":0}
  59. info: [debug] [BOOTSTRAP] [debug] Closed client connection
  60. info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: numtests=1
  61. info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=.
  62. info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
  63. info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: test=testRunServer
  64. info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: class=io.appium.android.bootstrap.Bootstrap
  65. info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: current=1
  66. info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: 0
  67. info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=
  68. info: [debug] [UIAUTOMATOR STDOUT] Test results for WatcherResultPrinter=.
  69. info: [debug] [UIAUTOMATOR STDOUT] Time: 16.286
  70. info: [debug] [UIAUTOMATOR STDOUT] OK (1 test)
  71. info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: -1
  72. info: [debug] UiAutomator shut down normally
  73. info: [debug] executing cmd: "C:\Program Files\android-sdk-windows\platform-tools\adb.exe" -s 253254d5 shell "am force-stop com.android.chrome"
  74. info: [debug] Stopping logcat capture
  75. info: [debug] Logcat terminated with code null, signal SIGTERM
  76. info: [debug] Cleaning up appium session
  77. info: [debug] Responding to client with success: {"status":0,"value":null,"sessionId":"de7dd879fcd4c51ea8b9653da996b15d"}
  78. info: <-- DELETE /wd/hub/session/de7dd879fcd4c51ea8b9653da996b15d 200 1590.341 ms - 72 {"status":0,"value":null,"sessionId":"de7dd879fcd4c51ea8b9653da996b15d"}
  79. Killed Node Server.
  80. Node Server Process Ended
复制代码
请各位大神指点一二,这个问题困扰了很久了,多谢(>_<)
回复 支持 反对

使用道具 举报

该用户从未签到

4#
发表于 2017-11-23 12:17:10 | 只看该作者
1.没有排版
2.错误日志没有给出
回复 支持 反对

使用道具 举报

该用户从未签到

5#
发表于 2017-11-23 12:21:51 | 只看该作者
首先你的页面是这样的:
  1. (function () {
  2.     var self = null
  3.     var welcome = {
  4.         init: function () {
  5.             self = this
  6.             self.bind()
  7.         },
  8.         bind: function () {
  9.             $(document)
  10.             .on('tap', '#register', function () {
  11.                 location.assign('register_first_step.html?v=' + new Date().getTime())
  12.             })
  13.             .on('tap', '#login', function () {
  14.                 location.assign('login.html?v=' + new Date().getTime())
  15.             })
  16.         }
  17.     }
  18.     welcome.init()
  19. })()
复制代码


也就是说 click 估计压根不能触发你的 tap 事件,所以肯定不能跳转。
回复 支持 反对

使用道具 举报

该用户从未签到

6#
发表于 2017-11-23 12:22:39 | 只看该作者

试试看执行下面的脚本,我测试是可以的。

  1. function triggerEventOnPage(selector, eventName, memo) {
  2.     //casper.evaluate(function(selector, eventName, memo){
  3.         var event;
  4.         var element = document.querySelector(selector);

  5.         event = document.createEvent("Event");
  6.         event.initEvent(eventName, true, true);
  7.         event.memo = memo || { };

  8.         element.dispatchEvent(event);
  9.     //}, selector, eventName, memo);
  10.     //wait();
  11. }
  12. triggerEventOnPage("#register", "tap");
复制代码

回复 支持 反对

使用道具 举报

该用户从未签到

7#
 楼主| 发表于 2017-11-23 13:09:57 | 只看该作者
草帽路飞UU 发表于 2017-11-23 12:22
试试看执行下面的脚本,我测试是可以的。

谢谢了,尝试了下确实可以。
回复 支持 反对

使用道具 举报

本版积分规则

关闭

站长推荐上一条 /1 下一条

小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

GMT+8, 2024-11-23 03:41 , Processed in 0.070594 second(s), 22 queries .

Powered by Discuz! X3.2

© 2001-2024 Comsenz Inc.

快速回复 返回顶部 返回列表