Appium appium 从 native 切换 webview,一直失败

闲看亭花落花开 · May 11, 2023 · Last by 闲看亭花落花开 replied at May 22, 2023 · 5430 hits

环境: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)


共收到 2 条回复 时间 点赞

看下你打印的 print("切换所属:",now)
是不是你需要的 webview
我之前遇到个问题,就是因为后来开着什么,导致同时存在几个 webview,切换就会出问题,没切换到我想要的 webview 上

Barry250 回复

执行不到这,在 switch 的时候就报错了😥

闲看亭花落花开 关闭了讨论 03 Jul 18:27
需要 Sign In 后方可回复, 如果你还没有账号请点击这里 Sign Up