环境:appiumV1.22.3、App 是混合开发使用 X5 内核
详细:已让开发同学设置 android.webkit.WebView 元素的 setWebContentsDebuggingEnabled 属性设置为 true,获取到 contexts 列表为 ['NATIVE_APP', 'WEBVIEW_merkava.app.kilowatt'],切换到 WEBVIEW_merkava.app.kilowatt 时,提示 chromedrive 创建 session 失败,版本看了也是对应的。
代码:
desired_caps_2 ={
    'platformName': 'Android',
    'deviceName': 'CLB7N18622009475',
    'platformVersion': '10',
    'appPackage': 'merkava.app.kilowatt',
    'appActivity': '.ui.splash.SplashActivity',
    'unicodeKeyboard': True,
    'resetKeyboard': True,
    'noReset': True,
    'newCommandTimeout': 600,
    'automationName': 'UIAutomator2',
    'autoWebview': False,
    'showChromedriverLog': True,
    'setWebContentsDebuggingEnabled': True,
    'chromeOptions':
        {
            'androidPackage': 'merkava.app.kilowatt',
            'androidUseRunningApp': False,
            'androidProcess': 'merkava.app.kilowatt',
        },
}
contexts = driver.contexts
print(contexts)
s = driver.current_activity
print(s)
driver.switch_to.context(contexts[1])
now = driver.current_context
print("切换所属:",now)

