javaandroidviewgroupandroid-viewgroup

How to locate the Android ViewGroup element?


There is a calendar layout hierarchy. I'd like to locate each element in the ViewGroup. I can achieve it by hardcoding the Whole XPath, apparently it's quite un-efficient. Is there any better approach to do this?

Screenshot and the Hierarchy are given blow:

enter image description here

enter image description here


Solution

  • I've figured out a simple way myself:

    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();