问答 最新版,appium context 如何在 native_app 和 webview 来回切换呢?

CC · 2023年02月15日 · 最后由 Skywalker 回复于 2024年02月01日 · 5577 次阅读

目前native_app切换到 webview 可以,但是切换回来会无法获取page_source(空的),也就是 find_element 也找不到

Timed out after 15525ms waiting for the root AccessibilityNodeInfo in the active window. 
Make sure the active window is not constantly hogging the main UI thread (e.g. the application is being idle long enough), 
so the accessibility manager could do its work

请教一下各位,这个怎么解决?

共收到 6 条回复 时间 点赞

打印一下当前开启几个 window 看看是不是切换到了一个空白的 window 里面

CC #2 · 2023年02月16日 Author
微凉 回复

切换到 webview 的时候,也切换到了某个 window(不切换的话无法获取到 webview 里的内容)
之后再切换回 native_app 后,current_window_handle 和 window_handles 无法打印了,直接报错
启用了 appium:enableMultiWindows,打印 page_source 会显示通知栏的 xml 代码,但是屏幕中间的微信是没有的

CC 回复

你是微信里面是吧,微信是有好几个 window 的 你应该是切换回来的时候切换错了

CC #4 · 2023年02月17日 Author
微凉 回复

最新情况:

我发现不切换contextwindow,单纯的点击进入公众号文章
然后 press_code(4) 返回公众号文章列表
也会出现这种情况,与contextwindow_handle无关
我怀疑是谷歌官方 uiautomator的问题,但是不知道该如何解决
因为appium-uiautomator2-server最终调用的还是uiautomatorgetQueryController
https://android.googlesource.com/platform/frameworks/uiautomator/+/61ce05bd4fd5ffc1f036c7c02c9af7cb92d6ec50/src/com/android/uiautomator/core/UiObject.java

public AccessibilityNodeInfo getAccessibilityRootNode() throws UiAutomator2Exception {
    Object queryController = invoke(getMethod(UiDevice.class, "getQueryController"), Device.getUiDevice());
    return (AccessibilityNodeInfo) invoke(getMethod(queryController.getClass(), "getRootNode"), queryController);
}

我也遇到了这个问题

但我暂时找到一个不那么靠谱的办法,就是在每次切换后重建一个 session,来覆盖原来的 session
具体代码如下
driver.start_session(DESIRED_CAPS)

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