在自动化的过程中经常会遇到元素位置存在前后变动,或者存在相同元素的情况,我们需要依赖目标元素周边或者上下级综合去定位元素。以下稍微写了一个案例,就是针对这种情况。
例如以下xpath,我需要定位ImageView,但是这个界面中存在大量的ImageView,此时我需要通过综合方式去定位。
xpath=//android.widget.TextView[@text='推荐单品']/parent::android.widget.RelativeLayout/following-sibling::androidx.recyclerview.widget.RecyclerView/android.widget.RelativeLayout[1]/android.widget.FrameLayout/android.widget.FrameLayout/android