Appium [已解决] python+appium 切换 webview 时报错

悟空 · 2016年08月17日 · 最后由 小红帽 回复于 2017年10月24日 · 2132 次阅读

平台:python+appium
脚本代码:webview = driver.contexts[-1]
driver.switch_to.context(webview)
我已经找到 webview,也已经下载了最新的 chromedriver(2.18-2.23 都试过了)和 Chrome(52.XXX),手机端也安装了 chrome(52.XXX),总是报下面这个错误,这里还需要什么操作吗?
运行到这一句之后日志中显示返回 Error Chrome version must be >= 43.0.2357.0\n (Driver info: chromedriver=2.18.343845 (73dd713ba7fbfb73cbb51..

报错日志

info: [debug] Connecting to chrome-backed webview
info: Chromedriver: Changed state to 'starting'
info: Chromedriver: Set chromedriver binary as: C:\Program Files (x86)\Appium\node_modules\appium\node_modules\appium-chromedriver\chromedriver\win\chromedriver.exe
info: Chromedriver: 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: Chromedriver: No old chromedrivers seemed to exist
info: Chromedriver: Spawning chromedriver with: C:\Program Files (x86)\Appium\node_modules\appium\node_modules\appium-chromedriver\chromedriver\win\chromedriver.exe --url-base=wd/hub --port=9515
info: Chromedriver: [STDOUT] Starting ChromeDriver 2.18.343845 (73dd713ba7fbfb73cbb514e62641d8c96a94682a) on port 9515
Only local connections are allowed.
info: JSONWP Proxy: Proxying [GET /status] to [GET http://127.0.0.1:9515/wd/hub/status] with no body
info: JSONWP Proxy: Got response with status 200: "{\"sessionId\":\"\",\"status\":0,\"value\":{\"build\":{\"version\":\"alpha\"},\"os\":{\"arch\":\"x86_64\",\"name\":\"Windows NT\",\"version\":\"6.1 SP1\"}}}"
info: JSONWP Proxy: Proxying [POST /session] to [POST http://127.0.0.1:9515/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.XXXXXXXX","androidUseRunningApp":true,"androidDeviceSerial":"85GBBME22774"}}}
info: JSONWP Proxy: Got response with status 200: {"sessionId":"9d1b2aa422a3dfabef53ebf2f278c0c2","status":13,"value":{"message":"unknown error: Chrome version must be >= 43.0.2357.0\n (Driver info: chromedriver=2.18.343845 (73dd713ba7fbfb73cbb51...
info: JSONWP Proxy: Proxying [POST /session] to [POST http://127.0.0.1:9515/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.XXXXXXXX","androidUseRunningApp":true,"androidDeviceSerial":"85GBBME22774"}}}
info: JSONWP Proxy: Got response with status 200: {"sessionId":"2d764277891840393aa45f276c896102","status":13,"value":{"message":"unknown error: Chrome version must be >= 43.0.2357.0\n (Driver info: chromedriver=2.18.343845 (73dd713ba7fbfb73cbb51...
info: JSONWP Proxy: Proxying [POST /session] to [POST http://127.0.0.1:9515/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.XXXXXXXX","androidUseRunningApp":true,"androidDeviceSerial":"85GBBME22774"}}}
info: JSONWP Proxy: Got response with status 200: {"sessionId":"5a7d56be441c54bc2297bf2a56e3c9b6","status":13,"value":{"message":"unknown error: Chrome version must be >= 43.0.2357.0\n (Driver info: chromedriver=2.18.343845 (73dd713ba7fbfb73cbb51...
info: JSONWP Proxy: Proxying [POST /session] to [POST http://127.0.0.1:9515/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.XXXXXXXX","androidUseRunningApp":true,"androidDeviceSerial":"85GBBME22774"}}}
info: JSONWP Proxy: Got response with status 200: {"sessionId":"621c91332cf2b25fcc8c9624026f7e48","status":13,"value":{"message":"unknown error: Chrome version must be >= 43.0.2357.0\n (Driver info: chromedriver=2.18.343845 (73dd713ba7fbfb73cbb51...
info: Chromedriver: Changed state to 'stopped'
error: Chromedriver: Chromedriver exited unexpectedly with code null, signal SIGTERM
warn: Chromedriver for context WEBVIEW_com.XXXXXXXX stopped unexpectedly
warn: Chromedriver quit unexpectedly, but it wasn't the active context, ignoring
error: Chromedriver: Error: An unknown server-side error occurred while processing the command. (Original error: unknown error: Chrome version must be >= 43.0.2357.0
(Driver info: chromedriver=2.18.343845 (73dd713ba7fbfb73cbb514e62641d8c96a94682a),platform=Windows NT 6.1 SP1 x86_64))
at JWProxy.command$ (lib/proxy.js:133:15)
at tryCatch (C:\Program Files (x86)\Appium\node_modules\appium\node_modules\appium-chromedriver\node_modules\appium-jsonwp-proxy\node_modules\babel-runtime\regenerator\runtime.js:67:40)
at GeneratorFunctionPrototype.invoke as _invoke
at GeneratorFunctionPrototype.prototype.(anonymous function) as next
at GeneratorFunctionPrototype.invoke (C:\Program Files (x86)\Appium\node_modules\appium\node_modules\appium-chromedriver\node_modules\appium-jsonwp-proxy\node_modules\babel-runtime\regenerator\runtime.js:136:37)
at bound (domain.js:284:14)
at GeneratorFunctionPrototype.runBound (domain.js:297:12)
at run (C:\Program Files (x86)\Appium\node_modules\appium\node_modules\appium-chromedriver\node_modules\appium-jsonwp-proxy\node_modules\babel-runtime\node_modules\core-js\library\modules\es6.promise.js:89:39)
at C:\Program Files (x86)\Appium\node_modules\appium\node_modules\appium-chromedriver\node_modules\appium-jsonwp-proxy\node_modules\babel-runtime\node_modules\core-js\library\modules\es6.promise.js💯28
at flush (C:\Program Files (x86)\Appium\node_modules\appium\node_modules\appium-chromedriver\node_modules\appium-jsonwp-proxy\node_modules\babel-runtime\node_modules\core-js\library\modules\$.microtask.js:17:13)
at process._tickDomainCallback (node.js:381:11)
{ [Error: An unknown server-side error occurred while processing the command. (Original error: unknown error: Chrome version must be >= 43.0.2357.0
(Driver info: chromedriver=2.18.343845 (73dd713ba7fbfb73cbb514e62641d8c96a94682a),platform=Windows NT 6.1 SP1 x86_64))]
status: 13,
value: { message: 'unknown error: Chrome version must be >= 43.0.2357.0\n (Driver info: chromedriver=2.18.343845 (73dd713ba7fbfb73cbb514e62641d8c96a94682a),platform=Windows NT 6.1 SP1 x86_64)' },
httpCode: 200 }
info: <-- POST /wd/hub/session/36325a79-8d23-43e5-88c4-e03e18e4183d/context - - ms - -
undefined

共收到 9 条回复 时间 点赞

python 不用切换 webview

#1 楼 @chungeguo 有时候我也没切换能成功

#2 楼 @heminwon python,我是从头到尾,都没有切换过,完全可以正常使用的

#3 楼 @chungeguo 我试了一下不切换,不会报错了。但是直接用比如 find_element_by_id 或者 by_xpath 定位 webview 中的元素,是无法找到元素的,请问这里还需要怎么操作?这个问题我卡了两天,现在还没有什么头绪。请再指点一下,谢谢了。

#4 楼 @yaojun1986 问题解决了吗?请指点下,谢谢啦~

#4 楼 @yaojun1986 web 元素使用 ACCESSIBILITY_ID

#6 楼 @chungeguo 非常感谢,的确是这样的。

@chungeguo 没有 ACCESSIBILITY_ID 属性的怎么寻找

@chungeguo 你好!
请问微信公众号和小程序,使用 python+appium,也不用切换 webview 吗?
如下的 webview,没有 ACCESSIBILITY_ID 值,怎么弄的呢?
如图是微信端,点击中信银行的小程序进入的界面:
如下 点击立即申请按钮

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册