如何使用正则表达式的 AndroidViewClient findViewWithText()

How to use AndroidViewClient findViewWithText() with regex

我有一个脚本可以监控通知屏幕页面。

我可以通过 "Culebra" 选项打开它 "UiDevice" -> "Open Notifications".
来自某些应用程序的通知错误消息具有不断变化的起始字符,只有像 "error for" 这样的常量模式很常见,但位于 TextView 错误消息的不同位置。

因此我不能将正则表达式与方法 findViewWithText(regex) 一起使用,因为它似乎使用正则表达式 match() 而不是正则表达式 search()。我的问题的另一个解决方案是将 traverse() 方法与我自己的转换方法一起使用,该方法可以对视图属性文本执行正则表达式 search(),但我无法弄清楚如何像正则表达式一样传递参数到我自己的转换方法!?

这对我来说很有效,可以触摸带有文本的通知 USB 调试已连接

vc.findViewWithTextOrRaise(re.compile('.*USB.*'), root=vc.findViewByIdOrRaise('id/no_id/3')).touch()
vc.sleep(_s)

注意这是修改后的 culebra 脚本,这就是 findViewWithTextOrRaise() 使用 root 参数将搜索限制在子树的原因,这可能并非在所有情况下都需要,但是使用起来更安全。

值得一提的是,这也有效

vc.findViewWithTextOrRaise(re.compile('.*debugging.*'), root=vc.findViewByIdOrRaise('id/no_id/3')).touch()