Appium appium 1.5.3 混合型 app,切换到 h5,无法定位元素。麻烦大神帮忙看下这个什么问题

· 2017年07月03日 · 最后由 蓝莓酱 回复于 2017年07月05日 · 2641 次阅读

切换到 h5 没有定位元素,日志如下,最后脚本报错

raise wde
selenium.common.exceptions.WebDriverException: Message: no such session
  (Driver info: chromedriver=2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4),platform=Mac OS X 10.12.1 x86_64)



["NATIVE_APP","WEBVIEW_so.dian.operatordebug","WEBVIEW_com.vphone.launcher"]
[debug] [AndroidDriver] Connecting to chrome-backed webview context 'WEBVIEW_so.dian.operatordebug'
[debug] [Chromedriver] Changed state to 'starting'

[Chromedriver] Set chromedriver binary as: /Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/appium-android-driver/node_modules/appium-chromedriver/chromedriver/mac/chromedriver

[Chromedriver] Killing any old chromedrivers, running: pkill -15 -f "/Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/appium-android-driver/node_modules/appium-chromedriver/chromedriver/mac/chromedriver.*--port=9515"
[Chromedriver] No old chromedrivers seemed to exist
[Chromedriver] Spawning chromedriver with: /Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/appium-android-driver/node_modules/appium-chromedriver/chromedriver/mac/chromedriver --url-base=wd/hub --port=9515 --adb-port=5037

[Chromedriver] [STDOUT] Starting ChromeDriver 2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4) on port 9515
Only local connections are allowed.

[JSONWP Proxy] Proxying [GET /status] to [GET http://127.0.0.1:9515/wd/hub/status] with no body

[Chromedriver] [STDERR] [warn] kq_init: detected broken kqueue; not using.: Undefined error: 0

[JSONWP Proxy] Got response with status 200: "{\"sessionId\":\"\",\"stat...

[JSONWP Proxy] Proxying [POST /session] to [POST http://127.0.0.1:9515/wd/hub/session] with body: {"desiredCapabilities":{"ch...

[HTTP] --> GET /wd/hub/status {}

[MJSONWP] Calling AppiumDriver.getStatus() with args: []

[MJSONWP] Responding to client with driver.getStatus() result: {"build":{"version":"1.5.3"...
[HTTP] <-- GET /wd/hub/status 200 23 ms - 83 

[JSONWP Proxy] Got response with status 200: {"sessionId":"b4353cddcfe84...

[debug] [Chromedriver] Changed state to 'online'

[MJSONWP] Responding to client with driver.setContext() result: null
[HTTP] <-- POST /wd/hub/session/92eb802a-778c-4ce9-8540-cc723d82e29e/context 200 61100 ms - 76 
[HTTP] --> GET /wd/hub/session/92eb802a-778c-4ce9-8540-cc723d82e29e/source {}
[MJSONWP] Driver proxy active, passing request on via HTTP proxy
[JSONWP Proxy] Proxying [GET /wd/hub/session/92eb802a-778c-4ce9-8540-cc723d82e29e/source] to [GET http://127.0.0.1:9515/wd/hub/session/b4353cddcfe8459654bee22f3b0928eb/source] with body: {}
[JSONWP Proxy] Got response with status 200: "{\"sessionId\":\"b4353cddc...
[JSONWP Proxy] Replacing sessionId b4353cddcfe8459654bee22f3b0928eb with 92eb802a-778c-4ce9-8540-cc723d82e29e
[HTTP] <-- GET /wd/hub/session/92eb802a-778c-4ce9-8540-cc723d82e29e/source 200 10 ms - 220 

[HTTP] --> GET /wd/hub/status {}

[MJSONWP] Calling AppiumDriver.getStatus() with args: []

[MJSONWP] Responding to client with driver.getStatus() result: {"build":{"version":"1.5.3"...
[HTTP] <-- GET /wd/hub/status 200 11 ms - 83 

[BaseDriver] Shutting down because we waited 60 seconds for a command

[debug] [AndroidDriver] Shutting down Android driver

[Appium] Closing session, cause was 'New Command Timeout of 60 seconds expired. Try customizing the timeout using the 'newCommandTimeout' desired capability'
[Appium] Removing session 92eb802a-778c-4ce9-8540-cc723d82e29e from our master session list
[debug] [AndroidDriver] Stopping chromedriver for context WEBVIEW_so.dian.operatordebug
[debug] [Chromedriver] Changed state to 'stopping'
[JSONWP Proxy] Proxying [DELETE /] to [DELETE http://127.0.0.1:9515/wd/hub/session/b4353cddcfe8459654bee22f3b0928eb] with no body
[JSONWP Proxy] Got response with status 200: "{\"sessionId\":\"b4353cddc...
[debug] [Chromedriver] Changed state to 'stopped'
[debug] [ADB] Getting connected devices...

[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running /Users/lingfengzong/Downloads/android-sdk-macosx/platform-tools/adb with args: ["-P",5037,"-s","127.0.0.1:62001","shell","am","force-stop","so.dian.operatordebug"]

[debug] [ADB] Getting connected devices...

[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running /Users/lingfengzong/Downloads/android-sdk-macosx/platform-tools/adb with args: ["-P",5037,"-s","127.0.0.1:62001","shell","am","force-stop","io.appium.unlock"]

[debug] [ADB] Pressing the HOME button

[debug] [ADB] Getting connected devices...

[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running /Users/lingfengzong/Downloads/android-sdk-macosx/platform-tools/adb with args: ["-P",5037,"-s","127.0.0.1:62001","shell","input","keyevent",3]

[debug] [Logcat] Stopping logcat capture

[debug] [AndroidBootstrap] Sending command to android: {"cmd":"shutdown"}

[debug] [AndroidBootstrap] Received command result from bootstrap
[debug] [UiAutomator] Shutting down UiAutomator
[debug] [UiAutomator] Moving to state 'stopping'
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"shutdown"}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type SHUTDOWN
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"value":"OK, shutting down","status":0}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Closed client connection
[debug] [AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS: numtests=1
[debug] [AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS: stream=.
[debug] [AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
[debug] [AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS: test=testRunServer
[debug] [AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS: class=io.appium.android.bootstrap.Bootstrap
[debug] [AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS: current=1
[debug] [AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS_CODE: 0
[debug] [AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS: stream=
[debug] [AndroidBootstrap] [UIAUTO STDOUT] Test results for WatcherResultPrinter=.
[debug] [AndroidBootstrap] [UIAUTO STDOUT] Time: 139.284
[debug] [AndroidBootstrap] [UIAUTO STDOUT] OK (1 test)
[debug] [AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS_CODE: -1
[debug] [UiAutomator] UiAutomator shut down normally
[debug] [UiAutomator] Moving to state 'stopped'
[debug] [ADB] Attempting to kill all uiautomator processes
[debug] [ADB] Getting all processes with uiautomator
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running /Users/lingfengzong/Downloads/android-sdk-macosx/platform-tools/adb with args: ["-P",5037,"-s","127.0.0.1:62001","shell","ps","uiautomator"]

[ADB] No uiautomator process found to kill, continuing...
[debug] [UiAutomator] Moving to state 'stopped'

[HTTP] --> GET /wd/hub/status {}

[MJSONWP] Calling AppiumDriver.getStatus() with args: []

[MJSONWP] Responding to client with driver.getStatus() result: {"build":{"version":"1.5.3"...
[HTTP] <-- GET /wd/hub/status 200 12 ms - 83 

[HTTP] --> GET /wd/hub/status {}

[MJSONWP] Calling AppiumDriver.getStatus() with args: []

[MJSONWP] Responding to client with driver.getStatus() result: {"build":{"version":"1.5.3"...
[HTTP] <-- GET /wd/hub/status 200 61 ms - 83 

共收到 15 条回复 时间 点赞

no such session

#2 · 2017年07月03日 Author
回复

新手 不知道怎么解决

回复

a=dr.contexts
print (a)
跳转的时候,获取 webview 的 context,然后跳转过去

#4 · 2017年07月03日 Author
回复

代码 没有问题,你看下我帖的日志,是跳转了 但是没有继续定位元素。

[debug] [AndroidDriver] Connecting to chrome-backed webview context 'WEBVIEW_so.dian.operatordebug'
[debug] [Chromedriver] Changed state to 'starting'

回复

等待时间设置长一点,然后检查一下 webview 的定位写的对不对

#14 · 2017年07月03日 Author
回复


应该不是等待时间到问题

[BaseDriver] Shutting down because we waited 60 seconds for a command
[debug] [AndroidDriver] Shutting down Android driver
[Appium] Closing session, cause was 'New Command Timeout of 60 seconds expired. Try customizing the timeout using the 'newCommandTimeout' desired capability'

试试看 newCommandTimeout 这个配置?类似这种:

capabilities.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, Constants.TIMEOUT);
#6 · 2017年07月03日 Author
恒温 回复

是的自己配置 capabilities 上的问题,已解决 谢谢大神

回复

这个问题好多人遇到过,你要不写写你的解决办法哇,我们学习学习

#4 · 2017年07月05日 Author
蓝莓酱 回复

我的问题是因为 chrome 和 chromedriver 版本不一致导致的。无法定位元素有很多问题,关键还是要看亮点,1 是 能否获取到上下文;2 就是 chrome 和 chromedriver 的版本的问题,需要根据实际情况去判断,可以参考 appium 日志来判断

回复

谢谢你哈~我当时的 chrome 版本对应 driver 是没问题的,切换上下文失败,能打印出类型就是 webview,就是运行的起来的时候拿不到。等我以后慢慢研究

#2 · 2017年07月05日 Author
蓝莓酱 回复

嗯 能打印出 webview 就看最后是代码报错 还是 appium 日志报错 再根据实际报错情况去解决

回复

恩恩,谢啦

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