What is best way to use xpath to find out an element

I am using below ways to click on dynamic elements using xpath in android.

  1. Using entire xpath from Root layout

Ex:
//android.widget.FrameLayout[1]/android.view.View[1]/android.widget.FrameLayout[2]/android.view.View[1]/android.widget.RelativeLayout[1]/android.widget.HorizontalScrollView[1]/android.widget.LinearLayout[1]

  1. Or using UiSelector:

ex: ‘-android uiautomator’, ‘new UiSelector().clickable(true).className(android.widget.TextView).index(1)’).click()

Both ways are working fine, but just curious to know which one is best option to search element faster…

1 Like