运行 hybrid 应用,切换到 webview 格式后报错

最近一直在搞 hybrid 啊。

  1. 从恒温跟恒捷帮我看第一匹 apk,那是 crosswalk 做的前端页面,貌似 windows 环境下,不支持。起初不知道,蒙头搞了 N 久,以为一定可以获取 webview
  2. 然后这次领导不依不饶,又给我 hybrid 前端页面是 webview 的 apk 了,这次可以获取到 webview 了,但是想切过去又报错,尼玛,怎么玩

我的代码:

#coding=utf-8
from appium import webdriver
from time import sleep

desired_caps = {}
#desired_caps['automationName'] = 'Selendroid'
desired_caps['automationName'] ="android"
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '4.4'
desired_caps['deviceName'] = '192.168.56.101:5555'
desired_caps['appPackage'] = 'com.jiudao.ccare'
desired_caps['appActivity'] = '.MainActivity'
desired_caps['autoWebview'] = 'true'
#desired_caps['androidDeviceSocket'] = 'chrome_devtools_remote'

dr = webdriver.Remote('http://192.168.10.65:4723/wd/hub', desired_caps)

dr.implicitly_wait(10)
a=dr.contexts
print (a)
#time.sleep(3)
dr.switch_to.context("WEBVIEW_com.jiudao.ccare")
username=dr.find_element_by_id("username")
username.clear()
username.send_keys("admin@WOT")
password=dr.find_element_by_id("username")
password.clear()
password.send_keys("1")
dr.close_app()
dr.quit()

这次我是获取到 webview 了,是 WEBVIEW_com.jiudao.ccare

然后还是报错,好蛋疼,请看以下报错信息

info: [debug] Pushing command to appium work queue: ["compressedLayoutHierarchy",{"compressLayout":false}]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"compressedLayoutHierarchy","params":{"compressLayout":false}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: compressedLayoutHierarchy
info: [debug] Getting device API level
info: [debug] executing cmd: D:\BaiduYunDownload\android-sdk\platform-tools\adb.exe -s 192.168.56.101:5555 shell "getprop ro.build.version.sdk"
info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":false,"status":0}
info: [debug] Device is at API Level 19
info: [debug] executing cmd: D:\BaiduYunDownload\android-sdk\platform-tools\adb.exe -s 192.168.56.101:5555 shell "am start -S -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -f 0x10200000 -n com.jiudao.ccare/.MainActivity"
info: [debug] Waiting for pkg "com.jiudao.ccare" and activity ".MainActivity" to be focused
info: [debug] Getting focused package and activity
info: [debug] executing cmd: D:\BaiduYunDownload\android-sdk\platform-tools\adb.exe -s 192.168.56.101:5555 shell "dumpsys window windows"
info: [debug] Setting auto webview
info: [debug] Getting a list of available webviews
info: [debug] executing cmd: D:\BaiduYunDownload\android-sdk\platform-tools\adb.exe -s 192.168.56.101:5555 shell "cat /proc/net/unix"
info: [debug] WEBVIEW_2473 mapped to pid 2473
info: [debug] Getting process name for webview
info: [debug] executing cmd: D:\BaiduYunDownload\android-sdk\platform-tools\adb.exe -s 192.168.56.101:5555 shell "ps"
info: [debug] Parsed pid: 2473 pkg: com.jiudao.ccare
info: [debug] from: u0_a64,2473,224,634096,51596,ffffffff,b7729586,R,com.jiudao.ccare
info: [debug] returning process name: com.jiudao.ccare
info: [debug] Available contexts: 
info: [debug] ["WEBVIEW_com.jiudao.ccare"]
info: [debug] Available contexts: NATIVE_APP,WEBVIEW_com.jiudao.ccare
info: [debug] Connecting to chrome-backed webview
info: [debug] Creating Chrome session
info: [debug] Set chromedriver binary as: E:\360Downloads\AppiumForWindows-1.3.4.1\Appium\node_modules\appium\build\chromedriver\windows\chromedriver.exe
info: [debug] Ensuring Chromedriver exists
info: [debug] 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 %b))
info: [debug] No old chromedrivers seemed to exist
info: [debug] Spawning chromedriver with: E:\360Downloads\AppiumForWindows-1.3.4.1\Appium\node_modules\appium\build\chromedriver\windows\chromedriver.exe
info: [debug] [CHROMEDRIVER] Starting ChromeDriver (v2.10.267521) on port 9515
Only local connections are allowed.
info: [debug] Making http request with opts: {"url":"http://127.0.0.1:9515/wd/hub/session","method":"POST","json":{"sessionId":null,"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.jiudao.ccare","androidUseRunningApp":true,"androidDeviceSerial":"192.168.56.101:5555"}}}}
info: [debug] [CHROMEDRIVER STDERR] [0.015][SEVERE]: Could not bind socket to 127.0.0.1:9515
info: [debug] [CHROMEDRIVER] Port not available. Exiting...
info: [debug] Chromedriver exited with code 1
info: [debug] Chromedriver exited unexpectedly
error: Chromedriver create session did not work. Status was 200 and body was {"sessionId":"9cf43a0e3328f67792eaf54e61744351","status":13,"value":{"message":"unknown error: Chrome version must be >= 33.0.1750.0\n  (Driver info: chromedriver=2.10.267521,platform=Windows NT 6.1 SP1 x86_64)"}}
error: Unhandled error: TypeError: Cannot read property 'status' of undefined
    at null.<anonymous> (E:\360Downloads\AppiumForWindows-1.3.4.1\Appium\node_modules\appium\lib\devices\android\android-hybrid.js:254:21)
    at null.<anonymous> (E:\360Downloads\AppiumForWindows-1.3.4.1\Appium\node_modules\appium\lib\devices\android\android-context-controller.js:68:23)
    at null.<anonymous> (E:\360Downloads\AppiumForWindows-1.3.4.1\Appium\node_modules\appium\lib\devices\android\android-hybrid.js:165:23)
    at null.<anonymous> (E:\360Downloads\AppiumForWindows-1.3.4.1\Appium\node_modules\appium\lib\devices\android\chromedriver.js:222:9)
    at Request._callback (E:\360Downloads\AppiumForWindows-1.3.4.1\Appium\node_modules\appium\lib\devices\common.js:121:5)
    at Request.self.callback (E:\360Downloads\AppiumForWindows-1.3.4.1\Appium\node_modules\appium\node_modules\request\request.js:121:22)
    at Request.EventEmitter.emit (events.js:98:17)
    at Request.<anonymous> (E:\360Downloads\AppiumForWindows-1.3.4.1\Appium\node_modules\appium\node_modules\request\request.js:985:14)
    at Request.EventEmitter.emit (events.js:117:20)
    at IncomingMessage.<anonymous> (E:\360Downloads\AppiumForWindows-1.3.4.1\Appium\node_modules\appium\node_modules\request\request.js:936:12) context: [POST /wd/hub/session {"desiredCapabilities":{"appPackage":"com.jiudao.ccare","deviceName":"192.168.56.101:5555","automationName":"android","appActivity":".MainActivity","platformName":"Android","platformVersion":"4.4","au]


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