如何定位 Android ViewGroup 元素?

How to locate the Android ViewGroup element?

有一个日历布局层次结构。我想定位 ViewGroup 中的每个元素。我可以通过对整个 XPath 进行硬编码来实现它,显然它效率很低。有没有更好的方法来做到这一点?

截图和Hierarchy给打击:

我自己想出了一个简单的方法:

Grid.androidDriver().findElementByXPath("//*[@resource-id='com.{path}:id/header_layout']/following::android.widget.LinearLayout[1]/descendant::android.widget.FrameLayout[@enabled='true']/android.widget.TextView[contains(@text,'"+date+"')]").click();