Appium测试微信公众号出错

问题

在公众号文章列表中,选择一篇文章进入,然后press_code(4) 退出
发现再获取page_source就会报错
我怀疑是谷歌官方 uiautomator 的问题,但是不知道该如何解决
看到这篇文章https://ceshiren.com/t/topic/14985
应该是一样的问题,不知道现在有没有解决方案?
开启了enableMultiWindows ,可以获取到通知栏那儿的电量、WiFi 信号等东西,屏幕中间没有
不开启直接报错

报错信息

和https://ceshiren.com/t/topic/14985一样

Traceback (most recent call last):
  File "D:\Workplace\Python\appium起步\lib\wechat.py", line 121, in <module>
    test(Wechat)
  File "D:\Workplace\Python\appium起步\lib\base.py", line 113, in test
    t.execute()
  File "D:\Workplace\Python\appium起步\lib\wechat.py", line 38, in execute
    save_str("./page_source.xml", self.driver.page_source)
  File "C:\Users\admin\.conda\envs\appium_start\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 541, in page_source
    return self.execute(Command.GET_PAGE_SOURCE)["value"]
  File "C:\Users\admin\.conda\envs\appium_start\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 440, in execute
    self.error_handler.check_response(response)
  File "C:\Users\admin\.conda\envs\appium_start\lib\site-packages\appium\webdriver\errorhandler.py", line 30, in check_response
    raise wde
  File "C:\Users\admin\.conda\envs\appium_start\lib\site-packages\appium\webdriver\errorhandler.py", line 26, in check_response
    super().check_response(response)
  File "C:\Users\admin\.conda\envs\appium_start\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 245, 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: Timed out after 15523ms 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
Stacktrace:
io.appium.uiautomator2.common.exceptions.UiAutomator2Exception: Timed out after 15523ms 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
	at io.appium.uiautomator2.utils.AXWindowHelpers.getActiveWindowRoot(AXWindowHelpers.java:79)
	at io.appium.uiautomator2.utils.AXWindowHelpers.getCachedWindowRoots(AXWindowHelpers.java:115)
	at io.appium.uiautomator2.core.AccessibilityNodeInfoDumper.toStream(AccessibilityNodeInfoDumper.java:229)
	at io.appium.uiautomator2.core.AccessibilityNodeInfoDumper.dumpToXml(AccessibilityNodeInfoDumper.java:246)
	at io.appium.uiautomator2.handler.Source.safeHandle(Source.java:54)
	at io.appium.uiautomator2.handler.request.SafeRequestHandler.handle(SafeRequestHandler.java:59)
	at io.appium.uiautomator2.server.AppiumServlet.handleRequest(AppiumServlet.java:267)
	at io.appium.uiautomator2.server.AppiumServlet.handleHttpRequest(AppiumServlet.java:261)
	at io.appium.uiautomator2.http.ServerHandler.channelRead(ServerHandler.java:68)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)
	at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)
	at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:435)
	at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:293)
	at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:267)
	at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:250)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)
	at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:266)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)
	at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1294)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
	at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:911)
	at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:131)
	at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:611)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:552)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:466)
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:438)
	at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:140)
	at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:144)
	at java.lang.Thread.run(Thread.java:764)

Appium 日志

y.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)\n\tat io.netty.channel.AbstractChannelHandlerCont...
[HTTP] <-- POST /session/d5502ea3-e7da-46d0-a765-74169f41f439/element 200 1363 ms - 137
[HTTP]
[HTTP] --> GET /session/d5502ea3-e7da-46d0-a765-74169f41f439/element/00000000-0000-0067-ffff-ffff00000540/displayed
[HTTP] {}
[HTTP] <-- GET /session/d5502ea3-e7da-46d0-a765-74169f41f439/element/00000000-0000-0067-ffff-ffff00000540/displayed 200 30 ms - 14
[HTTP]
[HTTP] --> GET /session/d5502ea3-e7da-46d0-a765-74169f41f439/element/00000000-0000-0067-ffff-ffff00000540/enabled
[HTTP] {}
[HTTP] <-- GET /session/d5502ea3-e7da-46d0-a765-74169f41f439/element/00000000-0000-0067-ffff-ffff00000540/enabled 200 33 ms - 14
[HTTP]
[HTTP] --> POST /session/d5502ea3-e7da-46d0-a765-74169f41f439/element
[HTTP] {"using":"xpath","value":"//android.widget.ImageView[@content-desc='设置']"}
[HTTP] <-- POST /session/d5502ea3-e7da-46d0-a765-74169f41f439/element 200 230 ms - 137
[HTTP]
[HTTP] --> POST /session/d5502ea3-e7da-46d0-a765-74169f41f439/element/00000000-0000-0067-ffff-ffff00000540/click
[HTTP] {"id":"00000000-0000-0067-ffff-ffff00000540"}
[HTTP] <-- POST /session/d5502ea3-e7da-46d0-a765-74169f41f439/element/00000000-0000-0067-ffff-ffff00000540/click 200 58 ms - 14
[HTTP]
[HTTP] --> GET /session/d5502ea3-e7da-46d0-a765-74169f41f439/contexts
[HTTP] {}
[HTTP] <-- GET /session/d5502ea3-e7da-46d0-a765-74169f41f439/contexts 200 562 ms - 59
[HTTP]
[HTTP] --> POST /session/d5502ea3-e7da-46d0-a765-74169f41f439/element
[HTTP] {"using":"xpath","value":"//android.widget.TextView[contains(@text,'春天')]"}
[AndroidUiautomator2Driver@4acc (d5502ea3)] Got response with status 404: {"sessionId":"493e12e7-c53a-444a-a913-e1a3c10b9a5f","value":{"error":"no such element","message":"An element could not be located on the page using the given search parameters","stacktrace":"io.appium.uiautomator2.common.exceptions.ElementNotFoundException: An element could not be located on the page using the given search parameters\n\tat io.appium.uiautomator2.handler.FindElement.findElement(FindElement.java:90)\n\tat io.appium.uiautomator2.handler.FindElement.safeHandle(FindElement.java:67)\n\tat io.appium.uiautomator2.handler.request.SafeRequestHandler.handle(SafeRequestHandler.java:59)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleRequest(AppiumServlet.java:267)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleHttpRequest(AppiumServlet.java:261)\n\tat io.appium.uiautomator2.http.ServerHandler.channelRead(ServerHandler.java:68)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)\n\tat io.netty.channel.AbstractChannelHandlerCont...
[HTTP] <-- POST /session/d5502ea3-e7da-46d0-a765-74169f41f439/element 200 2123 ms - 137
[HTTP]
[HTTP] --> POST /session/d5502ea3-e7da-46d0-a765-74169f41f439/element/00000000-0000-0069-ffff-ffff0000060b/click
[HTTP] {"id":"00000000-0000-0069-ffff-ffff0000060b"}
[HTTP] <-- POST /session/d5502ea3-e7da-46d0-a765-74169f41f439/element/00000000-0000-0069-ffff-ffff0000060b/click 200 59 ms - 14
[HTTP]
[HTTP] --> POST /session/d5502ea3-e7da-46d0-a765-74169f41f439/appium/device/press_keycode
[HTTP] {"keycode":4}
[HTTP] <-- POST /session/d5502ea3-e7da-46d0-a765-74169f41f439/appium/device/press_keycode 200 436 ms - 14
[HTTP]
[HTTP] --> GET /session/d5502ea3-e7da-46d0-a765-74169f41f439/source
[HTTP] {}
[AndroidUiautomator2Driver@4acc (d5502ea3)] Driver proxy active, passing request on via HTTP proxy
[AndroidUiautomator2Driver@4acc (d5502ea3)] Got response with status 500: {"sessionId":"493e12e7-c53a-444a-a913-e1a3c10b9a5f","value":{"error":"unknown error","message":"Timed out after 15523ms 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","stacktrace":"io.appium.uiautomator2.common.exceptions.UiAutomator2Exception: Timed out after 15523ms 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\n\tat io.appium.uiautomator2.utils.AXWindowHelpers.getActiveWindowRoot(AXWindowHelpers.java:79)\n\tat io.appium.uiautomator2.utils.AXWindowHelpers.getCachedWindowRoots(AXWindowHelpers.java:115)\n\tat io.appium.uiautomator2.core.AccessibilityNodeInfoDumper.toStream(AccessibilityNodeInfoDumper.java:229)\n\tat io.appium.uiautomat...
[HTTP] <-- GET /session/d5502ea3-e7da-46d0-a765-74169f41f439/source 500 15566 ms - 4620
[HTTP]
[HTTP] --> DELETE /session/d5502ea3-e7da-46d0-a765-74169f41f439
[HTTP] {}
[AppiumDriver@d258] Removing session d5502ea3-e7da-46d0-a765-74169f41f439 from our master session list
[AndroidUiautomator2Driver@4acc (d5502ea3)] Restoring hidden api policy to the device default configuration
[HTTP] <-- DELETE /session/d5502ea3-e7da-46d0-a765-74169f41f439 200 336 ms - 14
[HTTP]

环境

Appium 2.0.0-beta.53
uiautomator2

日志全发一下吧

发了

appium的日志也发一下哈

好的,发了

目前看来这个问题还没有解决

嗯嗯,我看到了这篇帖子,但是现在都2023年了
请问一下有什么修复办法吗

可以这样workaround:

  1. 重新开启一个新的session, 然后要操作小程序就切换context到小程序,self._driver.switch_to.context(“WEBVIEW_com.tencent.mm:appbrand0”), 要操作微信WebView, 就切换到self._driver.switch_to.context(“WEBVIEW_com.tencent.mm”)

  2. 当处于Web/hybrid 模式时, 可以试试appium inspector去启动新session, 观察左边是否能看到微信界面, 能看到,说明1好使, 不能就比较麻烦了, 要么降低微信版本, 要么恢复手机到出厂设置, 有可能安装的其他应用引起冲突, 简单卸载是不好使的

我是在小米note8,11 Pro试过,其他手机不清楚了.