问题:从 native 切换到 webview 的时候,长时间没有任何相应,然后挂掉~
机型:小米 5
rom:别人刷的 android8.0
appium server:1.8.1

也看到了类似差不多的问题,但是都没有能解决我现在的问题;
chrome 对应的 chromedriver 应该也没问题,然后我一直比较怀疑的是
'chromeOptions': {
'androidProcess': '进程名'
}
这个进程名是不是写错了

还有 switch_context 切换 context 的时候 切换的是不是切换错了

Log
Traceback (most recent call last):
  File "E:\pyworkspace\demos\webview_test\webview_tests.py", line 61, in <module>
    switch_context(driver)
  File "E:\pyworkspace\demos\webview_test\webview_tests.py", line 27, in switch_context
    driver.switch_to.context(context)
  File "D:\Program Files\Python\Python36\lib\site-packages\appium\webdriver\switch_to.py", line 31, in context
    self._driver.execute(MobileCommand.SWITCH_TO_CONTEXT, {'name': context_name})
  File "D:\Program Files\Python\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 314, in execute
    self.error_handler.check_response(response)
  File "D:\Program Files\Python\Python36\lib\site-packages\appium\webdriver\errorhandler.py", line 29, in check_response
    raise wde
  File "D:\Program Files\Python\Python36\lib\site-packages\appium\webdriver\errorhandler.py", line 24, in check_response
    super(MobileErrorHandler, self).check_response(response)
  File "D:\Program Files\Python\Python36\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: Failed to start Chromedriver session: An error occurred (Original error: chrome not reachable
  (Driver info: chromedriver=2.30.477700 (0057494ad8732195794a7b32078424f92a5fce41),platform=Windows NT 6.1.7601 SP1 x86_64))


代码 就是随便写的demo 就想去微信的小程序 拼多多里面去随便看测下
import os
import sys
sys.path.append(os.path.split(os.path.dirname(os.path.abspath(__file__)))[0])
import time
from appium import webdriver
from webview_test.driver_utils import DriverUtils


def switch_context(driver, context="WEBVIEW_com.tencent.mm"):

    contexts = driver.contexts
    print("contexts:%s" % contexts)
    if context in contexts:
        print(u"切换到相应的环境下面")
        driver.switch_to.context(context)
        return True
    else:
        print(u"没有切换到相应的环境下面,当前的环境为" + str(driver.context))
        return False


desired_caps = {
    'platformName': 'Android',
    'deviceName': 'b8320a1',
    'platformVersion': '8.0',
    'appPackage': 'com.tencent.mm',
    'appActivity': '.ui.LauncherUI',
    'unicodeKeyboard': 'True',
    'resetKeyboard': 'True',
    'noReset': True,
    # 'autoLaunch': False,
    'recreateChromeDriverSessions': True,
    'chromeOptions': {
        'androidProcess': 'com.tencent.mm:appbrand0'
    },
}

driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
contexts = driver.contexts
print("contexts:%s" % contexts)
time.sleep(3)
du = DriverUtils(driver)
print("向下滑动")
du.swipe_bottom()
print("向下滑动")
du.swipe_bottom()
time.sleep(3)
du.find_elem_by_name("拼多多微主页").click()
time.sleep(10)
switch_context(driver)
print("向上滑动")
du.swipe_top()
time.sleep(10)


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