Android 如何通过xpath方法使泛型Appium查找元素?

Android 如何通过xpath方法使泛型Appium查找元素?,android,python,selenium,appium,Android,Python,Selenium,Appium,我正在为我的应用程序编写测试用例,但我有一个问题。当我使用Genymotion作为emulator时。我在Appium inspector上获得了此路径,并为此路径创建了脚本: "//android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]/android.support.v4.view.ViewPager[

我正在为我的应用程序编写测试用例,但我有一个问题。当我使用Genymotion作为emulator时。我在Appium inspector上获得了此路径,并为此路径创建了脚本:

"//android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]/android.support.v4.view.ViewPager[1]/android.widget.RelativeLayout[1]/android.widget.Button[1]"
但如果我使用“HTC One E8”设备。我在Appium inspector上找到了以下路径:

"//android.support.v4.view.ViewPager[1]/android.widget.Button[1]"
我的脚本会失败吗?如果我使用不同的设备和模拟器。 它怎么可能是通用的


PS:我使用了
self.driver.find\u element\u by_android\u uiautomator('new UiSelector().resourceId(“欢迎按钮”\u meet\u hopi”)。单击()
之前,它在Ubuntu上的Appium上工作,在OSX上的Appium上不工作,如果你注意的话,
//android.support.v4.view.ViewPager[1]/android.widget.button[1]
是较大xpath的子字符串。将//视为搜索的起点。如果//android.support.v4.view.ViewPager[1]是唯一的元素,则可以将其用作起点。此外,如果希望xpath更加一致,那么应该使用更多标识属性,如name和id。查看此xpath备忘单以了解更多信息:@econoMichael你能分享cheet sheet链接吗?我如何获得模糊图像。@Mert你能分享你的UIAutomator的屏幕截图吗screen@sameerjoshi对不起,我链接了缩略图。给你:@econoMichael谢谢