Appium appium 无法切换到 webview,error: Chromedriver: Error: An unknown server-side error occurred while processing the command. (Original error: unknown error: Device d3099932 is not online

豆腐拌小葱 · 2017年07月31日 · 最后由 tester_111 回复于 2019年08月02日 · 1452 次阅读

用 Python 编写的脚本文件切换到熬 webview,时灵时不灵。报错提示 Chromedriver: Error: An unknown server-side error occurred while processing the command. (Original error: unknown error: Device d3099932 is not online,我是连的真机,用 adb devices 一直是能够查看到设备的,不应该出现这种情况呀, 想问一下究竟是什么情况,一下是我的代码和报错的地方。

def startApp(self):
        """
        启动微信
        字典desired_caps里面存放连接的手机的信息和要启动APP的packagename和主ACTIVITY
        :return:
        """
        desired_caps = {
            'platformName': 'Android',
            'fastReset': 'false',
            'deviceName': 'm1_note',
            'appPackage': 'com.tencent.mm',
            'appActivity': '.ui.LauncherUI',
            'fullReset': 'false',
            'unicodeKeyboard': 'True',
            'resetKeyboard': 'True',
            'chromeOptions': {
                'androidProcess': 'com.tencent.mm:tools'
            },
            'recreateChromeDriverSessions': True
        }

        self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)  # 启动app

    def intoTargetURL(self):
        self.driver.implicitly_wait(30)
        self.driver.find_element_by_name(u'我').click()
        self.driver.find_element_by_name(u'相册').click()
        time.sleep(2)
        self.driver.find_element_by_id('com.tencent.mm:id/mo').click()
        time.sleep(2)
        self.driver.find_element_by_id('com.tencent.mm:id/mo').click()
        time.sleep(2)
        print u'开始打印context'
        contexts = self.driver.contexts  # 获取当前页面的context
        print 'current contexts = ', contexts     ----->代码只执行到这
        for targetcontext in contexts:
            if targetcontext == 'WEBVIEW_com.tencent.mm:tools':
                self.driver.switch_to.context('WEBVIEW_com.tencent.mm:tools')
            elif targetcontext =='WEBVIEW_undefined':
                self.driver.switch_to.context('WEBVIEW_undefined')
        print self.driver.current_context

        self.driver.find_element_by_xpath('/html/body/div[1]/section[3]/div[2]/div[2]/ul/li[1]').click()

appium 报错:

info: [debug] Available contexts: NATIVE_APP,WEBVIEW_com.tencent.mm:appbrand0,WEBVIEW_com.tencent.mm:tools
info: [debug] Connecting to chrome-backed webview
info: Chromedriver: Changed state to 'starting'
info: Chromedriver: Set chromedriver binary as: D:\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: D:\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\":\"10.0\"}}}"
info: JSONWP Proxy: Proxying [POST /session] to [POST http://127.0.0.1:9515/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.tencent.mm","androidUseRunningApp":true,"androidProcess":"com.tencent.mm:tools","androidDeviceSerial":"d3099932"}}}
info: JSONWP Proxy: Got response with status 200: {"sessionId":"614fb425cabb4ff0e7eabb64b2731b7d","status":13,"value":{"message":"unknown error: Device d3099932 is not online\n  (Driver info: chromedriver=2.18.343845 (73dd713ba7fbfb73cbb514e62641d...
info: JSONWP Proxy: Proxying [POST /session] to [POST http://127.0.0.1:9515/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.tencent.mm","androidUseRunningApp":true,"androidProcess":"com.tencent.mm:tools","androidDeviceSerial":"d3099932"}}}
info: JSONWP Proxy: Got response with status 200: {"sessionId":"b15398c304323a6be7a45f7a45e0263c","status":13,"value":{"message":"unknown error: Device d3099932 is not online\n  (Driver info: chromedriver=2.18.343845 (73dd713ba7fbfb73cbb514e62641d...
info: JSONWP Proxy: Proxying [POST /session] to [POST http://127.0.0.1:9515/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.tencent.mm","androidUseRunningApp":true,"androidProcess":"com.tencent.mm:tools","androidDeviceSerial":"d3099932"}}}
info: JSONWP Proxy: Got response with status 200: {"sessionId":"5167f998c38c0883e03c7b0ee4da92a8","status":13,"value":{"message":"unknown error: Device d3099932 is not online\n  (Driver info: chromedriver=2.18.343845 (73dd713ba7fbfb73cbb514e62641d...
info: JSONWP Proxy: Proxying [POST /session] to [POST http://127.0.0.1:9515/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.tencent.mm","androidUseRunningApp":true,"androidProcess":"com.tencent.mm:tools","androidDeviceSerial":"d3099932"}}}
info: JSONWP Proxy: Got response with status 200: {"sessionId":"8ed028faafdd056fddf0634203236627","status":13,"value":{"message":"unknown error: Device d3099932 is not online\n  (Driver info: chromedriver=2.18.343845 (73dd713ba7fbfb73cbb514e62641d...
error: Chromedriver: Chromedriver exited unexpectedly with code null, signal SIGTERM
info: Chromedriver: Changed state to 'stopped'
warn: Chromedriver for context WEBVIEW_com.tencent.mm:tools 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: Device d3099932 is not online
  (Driver info: chromedriver=2.18.343845 (73dd713ba7fbfb73cbb514e62641d8c96a94682a),platform=Windows NT 10.0 x86_64))
    at JWProxy.command$ (lib/proxy.js:133:15)
    at tryCatch (D:\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] (D:\Program Files (x86)\Appium\node_modules\appium\node_modules\appium-chromedriver\node_modules\appium-jsonwp-proxy\node_modules\babel-runtime\regenerator\runtime.js:315:22)
    at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (D:\Program Files (x86)\Appium\node_modules\appium\node_modules\appium-chromedriver\node_modules\appium-jsonwp-proxy\node_modules\babel-runtime\regenerator\runtime.js:100:21)
    at GeneratorFunctionPrototype.invoke (D:\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:280:14)
    at GeneratorFunctionPrototype.runBound (domain.js:293:12)
 { Error: An unknown server-side error occurred while processing the command. (Original error: unknown error: Device d3099932 is not online
  (Driver info: chromedriver=2.18.343845 (73dd713ba7fbfb73cbb514e62641d8c96a94682a),platform=Windows NT 10.0 x86_64))
    at JWProxy.command$ (lib/proxy.js:133:15)
    at tryCatch (D:\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] (D:\Program Files (x86)\Appium\node_modules\appium\node_modules\appium-chromedriver\node_modules\appium-jsonwp-proxy\node_modules\babel-runtime\regenerator\runtime.js:315:22)
    at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (D:\Program Files (x86)\Appium\node_modules\appium\node_modules\appium-chromedriver\node_modules\appium-jsonwp-proxy\node_modules\babel-runtime\regenerator\runtime.js:100:21)
    at GeneratorFunctionPrototype.invoke (D:\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:280:14)
    at GeneratorFunctionPrototype.runBound (domain.js:293:12)
  status: 13,
  value: { message: 'unknown error: Device d3099932 is not online\n  (Driver info: chromedriver=2.18.343845 (73dd713ba7fbfb73cbb514e62641d8c96a94682a),platform=Windows NT 10.0 x86_64)' },
  httpCode: 200 }
(node:11252) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 7): Error: Looks like you passed in a response object as the first param to getResponseHandler. Err is always the first param! Fix your codes!
info: [debug] Didn't get a new command in 60 secs, shutting down...
info: Shutting down appium session
共收到 13 条回复 时间 点赞

切换到 webview 的时候,之所以用以下的代码是因为我打印 contexts 的时候有时候是 WEBVIEW_com.tencent.mm:tools,有时又是'WEBVIEW_undefined,所以我也很困惑。

if targetcontext == 'WEBVIEW_com.tencent.mm:tools':
self.driver.switch_to.context('WEBVIEW_com.tencent.mm:tools')
elif targetcontext =='WEBVIEW_undefined':
self.driver.switch_to.context('WEBVIEW_undefined')

好像和手机系统版本有关系,之前我用的安卓 4.3 的机器不会出现这个问题,换华为 5.0 的机器就会经常出现 underfined

王乐新 回复

我用的三星 Android7.0 的系统,appium 用的 1.4.6. 感觉问题多多啊 那除了换机器还有其他解决办法吗

同遇到这个问题,应该是 proxy 问题

spook 回复

那请问你解决了没呢?

升到 1.4.8 selenium 降到 2.4

spook 回复

我的始终不起作用 哎

关键是有时又能成功,大部分时候都不成功。

recreateChromeDriverSessions=true

你好,dfbxc ,你的这个帖子的问题解决了吗,我也遇到你这个问题了,而且是时灵时不灵,我打印了一下 driver.contexts,app 和 webview 都看到了,就是在切换的时候 driver.switch_to.context("WEBVIEW_xxx"),总是报错。求指导。

升级到 Appium 1.5 版本以上,问题解决

楼主,我也遇到这个问题,robotframework+appium,也是报这个错,实际手机一直在线,你最后怎么解决的

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