用 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


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