Appium 请教大家,appium+python 混合应用由 Native 切换到 Webview 报错 Device XXX is not online 的问题

wsygd · 2017年09月18日 · 最后由 muyucangtian 回复于 2019年07月17日 · 1313 次阅读

这些天基本上把能搜到的 关于 Native 切换到 Webview 的网页全看了,还是没有找到解决办法,请大家指点下,谢谢大家了!

首先我的脚本目前的情况:
1、在原生应用中执行没有问题,但是进入 webview 后,就无法找到控件,于是想到应该由 Native 切换到 Webview
2、使用driver.contexts,可以获取到["NATIVE_APP","WEBVIEW_xxx"]
3、在使用driver.switch_to.context('WEBVIEW_xxx') 就会报错 Device XXX is not online,
4、手机和电脑都安装了 chrome
5、手机版本:5.1;Appium 版本:1.6.4;手机 chrome 版本 61.0.3163.81;电脑 chrome 版本 61.0.3163.91
系统为 OSX10.11.6

代码及 appium 日志如下:

 desired_caps = {}
 desired_caps['deviceName'] = 'X2P0215821002481'   
 desired_caps['platformName'] = 'Android'
 desired_caps['platformVersion'] = '4.4.2'
 desired_caps['appPackage'] = 'com.baidu.hi'   
 desired_caps['chromeOptions'] = {'androidProcess': 'com.baidu.hi'}
 driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)

 #这里是操作native的,没有问题,代码略

if(driver.find_element_by_id('title_text').text=='签到'):  
     print '==========进入webview了=========='

 print 'switch'
 c=driver.contexts[1]
 print c
 driver.switch_to.context(c)

 print '转换完毕,现在开始操作webview'
 att_remark = driver.find_elements_by_xpath('//*[@id="attendance-remark"]')
 att_remark.send_keys('签到备注:这是一个appium自动化测试')

print c 打印出的是 WEBVIEW_xxx 没有问题,下一句转换就会报错

日志:

[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":0,"value":"签到"}
[debug] [AndroidBootstrap] Received command result from bootstrap
[debug] [MJSONWP] Responding to client with driver.getText() result: "签到"
[HTTP] <-- GET /wd/hub/session/a1fdcb0d-7d16-4d95-9e63-e339df493fcc/element/24/text 200 18 ms - 80 
[HTTP] --> GET /wd/hub/session/a1fdcb0d-7d16-4d95-9e63-e339df493fcc/contexts {}
[debug] [MJSONWP] Calling AppiumDriver.getContexts() with args: ["a1fdcb0d-7d16-4d95-9e63-e339df493fcc"]
[debug] [AndroidDriver] Getting a list of available webviews
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running '/Users/yujiaxi/Downloads/android-sdk-macosx/platform-tools/adb' with args: ["-P",5037,"-s","810EBMK4UNJA","shell","cat","/proc/net/unix"]
[debug] [AndroidDriver] WEBVIEW_30394 mapped to pid 30394
[debug] [AndroidDriver] Getting process name for webview
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running '/Users/yujiaxi/Downloads/android-sdk-macosx/platform-tools/adb' with args: ["-P",5037,"-s","810EBMK4UNJA","shell","ps"]
[debug] [AndroidDriver] Parsed pid: 30394 pkg: com.baidu.hi!
[debug] [AndroidDriver] from: u0_a242,30394,328,2249440,229832,ffffffff,00000000,S,com.baidu.hi
[debug] [AndroidDriver] returning process name: com.baidu.hi
[debug] [AndroidDriver] Found webviews: ["WEBVIEW_xxx'"]
[debug] [AndroidDriver] Available contexts: ["NATIVE_APP","WEBVIEW_xxx'"]
[debug] [MJSONWP] Responding to client with driver.getContexts() result: ["NATIVE_APP","WEBVIEW_xxx"]
[HTTP] <-- GET /wd/hub/session/a1fdcb0d-7d16-4d95-9e63-e339df493fcc/contexts 200 178 ms - 109 
[HTTP] --> POST /wd/hub/session/a1fdcb0d-7d16-4d95-9e63-e339df493fcc/context {"sessionId":"a1fdcb0d-7d16-4d95-9e63-e339df493fcc","name":"WEBVIEW_xxx'"}
[debug] [MJSONWP] Calling AppiumDriver.setContext() with args: ["WEBVIEW_xxx","a1fdcb0d-7d16-4d95-9e63-e339df493fcc"]
[debug] [AndroidDriver] Getting a list of available webviews
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running '/Users/yujiaxi/Downloads/android-sdk-macosx/platform-tools/adb' with args: ["-P",5037,"-s","810EBMK4UNJA","shell","cat","/proc/net/unix"]
[debug] [AndroidDriver] WEBVIEW_30394 mapped to pid 30394
[debug] [AndroidDriver] Getting process name for webview
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running '/Users/yujiaxi/Downloads/android-sdk-macosx/platform-tools/adb' with args: ["-P",5037,"-s","810EBMK4UNJA","shell","ps"]
[debug] [AndroidDriver] Parsed pid: 30394 pkg: com.baidu.hi!
[debug] [AndroidDriver] from: u0_a242,30394,328,2249440,229832,ffffffff,00000000,R,com.baidu.hi
[debug] [AndroidDriver] returning process name: com.baidu.hi
[debug] [AndroidDriver] Found webviews: ["WEBVIEW_xxx"]
[debug] [AndroidDriver] Available contexts: ["NATIVE_APP","WEBVIEW_xxx"]
[debug] [AndroidDriver] Connecting to chrome-backed webview context 'WEBVIEW_xxx'
[debug] [AndroidDriver] A port was not given, using random port: 8000
[debug] [Chromedriver] Changed state to 'starting'
[Chromedriver] Set chromedriver binary as: /usr/local/lib/node_modules/appium/node_modules/appium-chromedriver/chromedriver/mac/chromedriver
[Chromedriver] Killing any old chromedrivers, running: pkill -15 -f "/usr/local/lib/node_modules/appium/node_modules/appium-chromedriver/chromedriver/mac/chromedriver.*--port=8000"
[Chromedriver] No old chromedrivers seemed to exist
[Chromedriver] Spawning chromedriver with: /usr/local/lib/node_modules/appium/node_modules/appium-chromedriver/chromedriver/mac/chromedriver --url-base=wd/hub --port=8000 --adb-port=5037
[Chromedriver] [STDOUT] Starting ChromeDriver 2.18.343837 (52eb4041461e46a6b73308ebb19e85787ced4281) on port 8000
Only local connections are allowed.
[debug] [JSONWP Proxy] Proxying [GET /status] to [GET http://127.0.0.1:8000/wd/hub/status] with no body
[debug] [JSONWP Proxy] Got response with status 200: "{\"sessionId\":\"\",\"status\":0,\"value\":{\"build\":{\"version\":\"alpha\"},\"os\":{\"arch\":\"x86_64\",\"name\":\"Mac OS X\",\"version\":\"10.11.6\"}}}"
[debug] [JSONWP Proxy] Proxying [POST /session] to [POST http://127.0.0.1:8000/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.baidu.hi","androidUseRunningApp":true,"androidProcess":"com.baidu.hi","androidDeviceSerial":"810EBMK4UNJA"}}}
[debug] [JSONWP Proxy] Got response with status 200: {"sessionId":"2648ffed6892eced3ca7d4c3ff114524","status":13,"value":{"message":"unknown error: Device 810EBMK4UNJA is not online\n  (Driver info: chromedriver=2.18.343837 (52eb4041461e46a6b73308ebb19e85787ced4281),platform=Mac OS X 10.11.6 x86_64)"}}
[debug] [JSONWP Proxy] Proxying [POST /session] to [POST http://127.0.0.1:8000/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.baidu.hi","androidUseRunningApp":true,"androidProcess":"com.baidu.hi","androidDeviceSerial":"810EBMK4UNJA"}}}
[debug] [JSONWP Proxy] Got response with status 200: {"sessionId":"d930778f2b031e0e02408ebb52f83e64","status":13,"value":{"message":"unknown error: Device 810EBMK4UNJA is not online\n  (Driver info: chromedriver=2.18.343837 (52eb4041461e46a6b73308ebb19e85787ced4281),platform=Mac OS X 10.11.6 x86_64)"}}
[debug] [JSONWP Proxy] Proxying [POST /session] to [POST http://127.0.0.1:8000/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.baidu.hi","androidUseRunningApp":true,"androidProcess":"com.baidu.hi","androidDeviceSerial":"810EBMK4UNJA"}}}
[debug] [JSONWP Proxy] Got response with status 200: {"sessionId":"5cc70a3f72b1c86c20fb7b636e863923","status":13,"value":{"message":"unknown error: Device 810EBMK4UNJA is not online\n  (Driver info: chromedriver=2.18.343837 (52eb4041461e46a6b73308ebb19e85787ced4281),platform=Mac OS X 10.11.6 x86_64)"}}
[debug] [JSONWP Proxy] Proxying [POST /session] to [POST http://127.0.0.1:8000/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.baidu.hi","androidUseRunningApp":true,"androidProcess":"com.baidu.hi","androidDeviceSerial":"810EBMK4UNJA"}}}
[debug] [JSONWP Proxy] Got response with status 200: {"sessionId":"f01ab827c33078ad31ebdbc9894a7173","status":13,"value":{"message":"unknown error: Device 810EBMK4UNJA is not online\n  (Driver info: chromedriver=2.18.343837 (52eb4041461e46a6b73308ebb19e85787ced4281),platform=Mac OS X 10.11.6 x86_64)"}}
[Chromedriver] Chromedriver exited unexpectedly with code null, signal SIGTERM
[debug] [Chromedriver] Changed state to 'stopped'
[Chromedriver] Error: unknown error: Device 810EBMK4UNJA is not online
  (Driver info: chromedriver=2.18.343837 (52eb4041461e46a6b73308ebb19e85787ced4281),platform=Mac OS X 10.11.6 x86_64)
    at Chromedriver.callee$2$0$ (../../lib/chromedriver.js:176:15)
    at tryCatch (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)
    at GeneratorFunctionPrototype.invoke [as _invoke] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)
    at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
    at GeneratorFunctionPrototype.invoke (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37)
 Error: unknown error: Device 810EBMK4UNJA is not online
  (Driver info: chromedriver=2.18.343837 (52eb4041461e46a6b73308ebb19e85787ced4281),platform=Mac OS X 10.11.6 x86_64)
    at Chromedriver.callee$2$0$ (../../lib/chromedriver.js:176:15)
    at tryCatch (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)
    at GeneratorFunctionPrototype.invoke [as _invoke] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)
    at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
    at GeneratorFunctionPrototype.invoke (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37)
[MJSONWP] Encountered internal error running command: Error: unknown error: Device 810EBMK4UNJA is not online
  (Driver info: chromedriver=2.18.343837 (52eb4041461e46a6b73308ebb19e85787ced4281),platform=Mac OS X 10.11.6 x86_64)
    at Chromedriver.callee$2$0$ (../../lib/chromedriver.js:176:15)
    at tryCatch (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)
    at GeneratorFunctionPrototype.invoke [as _invoke] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)
    at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
    at GeneratorFunctionPrototype.invoke (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37)
[HTTP] <-- POST /wd/hub/session/a1fdcb0d-7d16-4d95-9e63-e339df493fcc/context 500 1131 ms - 338 

不知道为啥会报 Device XXX is not online,前面操作 native 是可以的,设备不可能 not online 呀?

共收到 5 条回复 时间 点赞

你好,请问你解决了么?我也遇到此问题了

我也遇到了这个问题,时好时坏,求解

请问这个问题解决了吗,我也遇到了,替换了对应版本的 Chromedriver 也没用

这问题有没有人回答啊。。。我也遇到了,查了全网没找到答案....😓

找了很久,没有找到解决的方法。

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