appium怎么定位activity.getWindowManager().addView生成的元素

各位大佬好,UI自动化中遇到开发使用activity.getWindowManager().addView生成的元素,无法定位
找过开发确认,activity.getWindowManager().addView生成的元素在xml里和hierarchy是一个层级,在使用driver.page_source打印安卓的activity_main.xml数据时发现,只有hierarchy里面的数据,
image
相当于appium只能定位hierarchy标签里面的元素。
之后又尝试了使用ui2的weditor确实获取到了activity.getWindowManager().addView生成的view的元素ID,使用appium执行脚本报找不到元素【Message: An element could not be located on the page using the given search parameters.】
资料:
app官网下载地址:BuzzCast-We Start Here,Live stream,Live video chat 不要使用模拟器,模拟器无法使用,使用真机
账号:15211111118 111111(此账号后面会删除了)
activity.getWindowManager().addView生成的是直播间的小窗口
小窗口操作方法:首页进入任意直播间,点击返回按钮,小窗口出现在右下角。
还请各位大佬帮忙解决下,或者提供下思路

是自定义控件?

不是自定义控件,开发把层级设置的比较高


目前发现weditor能获取到这个getwindowManager().addview添加的窗口的id,name属性信息,是不是用UI2可以定位到?已经验证appium运行报识别不到该元素

ua2里面有个特殊的的参数,可以试试 settings 的几个api

https://github.com/appium/appium-uiautomator2-driver#capabilities

  • ignoreUnimportantViews false
  • enableMultiWindows true

如果使用ua2定位,我的框架用的是appium怎么解决appium和ua2能同时链接手机呢?假期期间尝试了下,发现不能同时使用

在手机上杀掉进程就可以了,只能同时跑一个


还是不行,


现在知道什么原因了,在哪里设置appium元素对比为当前显示的所有元素,目前还没有查到资料

又尝试了allowInvisibleElements和enableMultiWindows,还是报错,

你把错误文字贴出来,截图里不全

Traceback (most recent call last):
File “/Users/changxingang/PycharmProjects/FaceCast_app_auto/dome/Dome.py”, line 30, in
print(driver.page_source)
File “/Users/changxingang/PycharmProjects/FaceCast_app_auto/venv/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py”, line 920, in page_source
return self.execute(Command.GET_PAGE_SOURCE)[‘value’]
File “/Users/changxingang/PycharmProjects/FaceCast_app_auto/venv/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py”, line 418, in execute
self.error_handler.check_response(response)
File “/Users/changxingang/PycharmProjects/FaceCast_app_auto/venv/lib/python3.8/site-packages/appium/webdriver/errorhandler.py”, line 31, in check_response
raise wde
File “/Users/changxingang/PycharmProjects/FaceCast_app_auto/venv/lib/python3.8/site-packages/appium/webdriver/errorhandler.py”, line 26, in check_response
super().check_response(response)
File “/Users/changxingang/PycharmProjects/FaceCast_app_auto/venv/lib/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py”, line 243, 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: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Boolean
Stacktrace:
java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Boolean
at io.appium.uiautomator2.model.settings.EnableMultiWindows.getValue(EnableMultiWindows.java:33)
at io.appium.uiautomator2.model.settings.EnableMultiWindows.getValue(EnableMultiWindows.java:21)
at io.appium.uiautomator2.utils.AXWindowHelpers.getCachedWindowRoots(AXWindowHelpers.java:105)
at io.appium.uiautomator2.core.AccessibilityNodeInfoDumper.toStream(AccessibilityNodeInfoDumper.java:169)
at io.appium.uiautomator2.core.AccessibilityNodeInfoDumper.dumpToXml(AccessibilityNodeInfoDumper.java:189)
at io.appium.uiautomator2.handler.Source.safeHandle(Source.java:38)
at io.appium.uiautomator2.handler.request.SafeRequestHandler.handle(SafeRequestHandler.java:38)
at io.appium.uiautomator2.server.AppiumServlet.handleRequest(AppiumServlet.java:252)
at io.appium.uiautomator2.server.AppiumServlet.handleHttpRequest(AppiumServlet.java:242)
at io.appium.uiautomator2.http.ServerHandler.channelRead(ServerHandler.java:44)
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.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:920)

以上这是所有的报错信息
下面是代码

你试试把’true’ 改成 True 试试

感谢校长大人,已经决绝,验证后只需要添加
desired_caps[‘ignoreUnimportantViews’] = False
desired_caps[‘enableMultiWindows’] = True
这两个设置就可以了
非常感谢

:slight_smile: 你们的app太特殊了,一般不会这么麻烦 。

关闭