开发者社区> 问答> 正文

切换 context 报错,有么有解决方法。

contexts = driver.contexts print(contexts[0]) print(contexts[1]) driver.switch_to.context(contexts[1]) now = driver.current_context print(now) 报错信息:

Traceback (most recent call last): File "C:\Users\Penn\AppData\Local\Programs\Python\Python36-32\lib\runpy.py", line 193, in run_module_as_main "main", mod_spec) File "C:\Users\Penn\AppData\Local\Programs\Python\Python36-32\lib\runpy.py", line 85, in run_code exec(code, run_globals) File "c:\Users\Penn.vscode\extensions\ms-python.python-2018.8.0\pythonFiles\experimental\ptvsd\ptvsd_main.py", line 211, in singlesession=args.single_session) File "c:\Users\Penn.vscode\extensions\ms-python.python-2018.8.0\pythonFiles\experimental\ptvsd\ptvsd_ main .py", line 205, in main debug_main(addr, name, kind, *extra, **kwargs) File "c:\Users\Penn.vscode\extensions\ms-python.python-2018.8.0\pythonFiles\experimental\ptvsd\ptvsd_local.py", line 30, in debug_main run_file(address, name, *extra, **kwargs) File "c:\Users\Penn.vscode\extensions\ms-python.python-2018.8.0\pythonFiles\experimental\ptvsd\ptvsd_local.py", line 64, in run_file run(argv, addr, **kwargs) File "c:\Users\Penn.vscode\extensions\ms-python.python-2018.8.0\pythonFiles\experimental\ptvsd\ptvsd_local.py", line 125, in _run _pydevd.main() File "c:\Users\Penn.vscode\extensions\ms-python.python-2018.8.0\pythonFiles\experimental\ptvsd\ptvsd_vendored\pydevd\pydevd.py", line 1752, in main globals = debugger.run(setup['file'], None, None, is_module) File "c:\Users\Penn.vscode\extensions\ms-python.python-2018.8.0\pythonFiles\experimental\ptvsd\ptvsd_vendored\pydevd\pydevd.py", line 1099, in run return self._exec(is_module, entry_point_fn, module_name, file, globals, locals) File "c:\Users\Penn.vscode\extensions\ms-python.python-2018.8.0\pythonFiles\experimental\ptvsd\ptvsd_vendored\pydevd\pydevd.py", line 1106, in _exec pydev_imports.execfile(file, globals, locals) # execute the script File "c:\Users\Penn.vscode\extensions\ms-python.python-2018.8.0\pythonFiles\experimental\ptvsd\ptvsd_vendored\pydevd_pydev_imps_pydev_execfile.py", line 25, in execfile exec(compile(contents+"\n", file, 'exec'), glob, loc) File "c:\Program Files\ETC\ETC_UI\ETC.py", line 53, in driver.switch_to.context(contexts[1]) File "C:\Users\Penn\AppData\Local\Programs\Python\Python36-32\lib\site-packages\appium\webdriver\switch_to.py", line 31, in context self._driver.execute(MobileCommand.SWITCH_TO_CONTEXT, {'name': context_name}) File "C:\Users\Penn\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 312, in execute response = self.command_executor.execute(driver_command, params) File "C:\Users\Penn\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 472, in execute return self._request(command_info[0], url, body=data) File "C:\Users\Penn\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 534, in _request resp = opener.open(request, timeout=self._timeout) File "C:\Users\Penn\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 526, in open response = self._open(req, data) File "C:\Users\Penn\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 544, in _open '_open', req) File "C:\Users\Penn\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 504, in _call_chain result = func(*args) File "C:\Users\Penn\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 1346, in http_open return self.do_open(http.client.HTTPConnection, req) File "C:\Users\Penn\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 1321, in do_open r = h.getresponse() File "C:\Users\Penn\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 1331, in getresponse response.begin() File "C:\Users\Penn\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 297, in begin version, status, reason = self._read_status() File "C:\Users\Penn\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 266, in _read_status raise RemoteDisconnected("Remote end closed connection without" http.client.RemoteDisconnected: Remote end closed connection without response Press any key to continue . . . Appium:

[HTTP] --> POST /wd/hub/session/8c961ae2-8333-4e71-bc0c-795dda358356/context [HTTP] {"name":"WEBVIEW_unknown","sessionId":"8c961ae2-8333-4e71-bc0c-795dda358356"} [debug] [W3C] Calling AppiumDriver.setContext() with args: ["WEBVIEW_unknown","8c961ae2-8333-4e71-bc0c-795dda358356"] [debug] [AndroidDriver] Getting a list of available webviews [debug] [ADB] Running 'C:\Program Files\android-sdk\sdk\platform-tools\adb.exe -P 5037 -s TCJRYLG6INQSKRP7 shell cat /proc/net/unix' [debug] [AndroidDriver] WEBVIEW_9697 mapped to pid 9697 [debug] [AndroidDriver] Getting process name for webview [debug] [ADB] Running 'C:\Program Files\android-sdk\sdk\platform-tools\adb.exe -P 5037 -s TCJRYLG6INQSKRP7 shell ps' [debug] [AndroidDriver] WEBVIEW_9714 mapped to pid 9714 [debug] [AndroidDriver] Getting process name for webview [debug] [ADB] Running 'C:\Program Files\android-sdk\sdk\platform-tools\adb.exe -P 5037 -s TCJRYLG6INQSKRP7 shell ps' [debug] [AndroidDriver] Returning process name: 'unknown' [debug] [AndroidDriver] Returning process name: 'unknown' [debug] [AndroidDriver] Found webviews: ["WEBVIEW_unknown","WEBVIEW_unknown"] [debug] [AndroidDriver] Available contexts: ["NATIVE_APP","WEBVIEW_unknown"] [debug] [AndroidDriver] Connecting to chrome-backed webview context 'WEBVIEW_unknown' [debug] [AndroidDriver] A port was not given, using random port: 8000 [debug] [Chromedriver] Changed state to 'starting' [debug] [Chromedriver] The following Chromedriver executables were found: [debug] [Chromedriver] C:/Users/Penn/AppData/Roaming/npm/node_modules/appium/node_modules/appium-chromedriver/chromedriver/win/chromedriver.exe (minimum Chrome version '57.0.2987') [debug] [ADB] Getting package info for 'com.google.android.webview' [debug] [ADB] Running 'C:\Program Files\android-sdk\sdk\platform-tools\adb.exe -P 5037 -s TCJRYLG6INQSKRP7 shell dumpsys package com.google.android.webview' [debug] [Chromedriver] Found Chrome bundle 'com.google.android.webview' version '62.0.3202' [debug] [Chromedriver] Found 1 Chromedriver executable capable of automating Chrome '62.0.3202'. [debug] [Chromedriver] Choosing the most recent, 'C:/Users/Penn/AppData/Roaming/npm/node_modules/appium/node_modules/appium-chromedriver/chromedriver/win/chromedriver.exe'. [debug] [Chromedriver] If a specific version is required, specify it with the chromedriverExecutabledesired capability. [Chromedriver] Set chromedriver binary as: C:/Users/Penn/AppData/Roaming/npm/node_modules/appium/node_modules/appium-chromedriver/chromedriver/win/chromedriver.exe [debug] [Chromedriver] Killing any old chromedrivers, running: FOR /F "usebackq tokens=5" %a in (netstat -nao ^| findstr /R /C:"8000 ") do (FOR /F "usebackq" %b in (TASKLIST /FI "PID eq %a" ^| findstr /I chromedriver.exe) do (IF NOT %b=="" TASKKILL /F /PID %a)) [Chromedriver] No old chromedrivers seemed to exist [debug] [Chromedriver] Cleaning any old adb forwarded port socket connections [debug] [ADB] List forwarding ports [debug] [ADB] Running 'C:\Program Files\android-sdk\sdk\platform-tools\adb.exe -P 5037 -s TCJRYLG6INQSKRP7 forward --list' [Chromedriver] Spawning chromedriver with: C:/Users/Penn/AppData/Roaming/npm/node_modules/appium/node_modules/appium-chromedriver/chromedriver/win/chromedriver.exe --url-base=wd/hub --port=8000 --adb-port=5037 --verbose [debug] [Chromedriver] Chromedriver version: '2.29.461591' [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":"Windows NT","version":"10.0.17134"}}}" [debug] [JSONWP Proxy] Proxying [POST /session] to [POST http://127.0.0.1:8000/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.tencent.mm","androidUseRunningApp":true,"androidProcess":"com.tencent.mm:tools","androidDeviceSerial":"TCJRYLG6INQSKRP7"}}} [debug] [JSONWP Proxy] Got response with status 200: {"sessionId":"e4fe0100c0e99ef53c9a1beecb61e15f","status":100,"value":{"message":"chrome not reachable\n (Driver info: chromedriver=2.29.461591 (62ebf098771772160f391d75e589dc567915b233),platform=Windows NT 10.0.17134 x86_64)"}} [Chromedriver] Error: Failed to start Chromedriver session: An error occurred (Original error: chrome not reachable [Chromedriver] (Driver info: chromedriver=2.29.461591 (62ebf098771772160f391d75e589dc567915b233),platform=Windows NT 10.0.17134 x86_64)) [Chromedriver] at Object.wrappedLogger.errorAndThrow (C:\Users\Penn\AppData\Roaming\npm\node_modules\appium\node_modules\appium-support\lib\logging.js:78:13) [Chromedriver] at Chromedriver.callee$2$0$ (C:\Users\Penn\AppData\Roaming\npm\node_modules\appium\node_modules\appium-chromedriver\lib\chromedriver.js:411:13) [Chromedriver] at tryCatch (C:\Users\Penn\AppData\Roaming\npm\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:67:40) [Chromedriver] at GeneratorFunctionPrototype.invoke [as _invoke] (C:\Users\Penn\AppData\Roaming\npm\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:315:22) [Chromedriver] at GeneratorFunctionPrototype.prototype.(anonymous function) [as throw] (C:\Users\Penn\AppData\Roaming\npm\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:100:21) [Chromedriver] at GeneratorFunctionPrototype.invoke (C:\Users\Penn\AppData\Roaming\npm\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:136:37) [Chromedriver] at [debug] [JSONWP Proxy] Proxying [POST /session] to [POST http://127.0.0.1:8000/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.tencent.mm","androidUseRunningApp":true,"androidProcess":"com.tencent.mm:tools","androidDeviceSerial":"TCJRYLG6INQSKRP7"}}} [debug] [AndroidBootstrap] Emitting alert message... [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Emitting system alert message [debug] [JSONWP Proxy] Got response with status 200: {"sessionId":"83c0b5de47a260402971260f99aea264","status":100,"value":{"message":"chrome not reachable\n (Driver info: chromedriver=2.29.461591 (62ebf098771772160f391d75e589dc567915b233),platform=Windows NT 10.0.17134 x86_64)"}}

展开
收起
zxp-0601 2020-01-07 16:49:03 2613 0
1 条回答
写回答
取消 提交回答
  • 报错明明是版本不对,你把appiun日志贴出来

    2020-01-07 16:49:16
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载