(class=android.widget.LinearLayout,resource-id=settings_language_selection_toggle,index=1 )
(class=android.widget.RelativeLayout,index=0)
(class=android.widget.LinearLayout,resource-id=widget_frame, index=1)
(class=android.widget.Switch,resource-id=switchWidget, index=0)
///////你可以看看下面元素的层次表示法
层次图像视图。
***我试图通过在appium Android的java上写下面的代码来达到开关按钮,但没有成功。
@AndroidFindBy(xpath ="new UiSelector().resourceId(\"com.idscan.mjcs.sample:id/settings_language_selection_toggle\").instance(1).getChildById(new UiSelector().className(\"android.widget.Switch\")
你在XPath策略中使用了UiSelector语法。这就是为什么它不能工作的原因。试试这个。
@AndroidFindBy(uiAutomator = "resourceId(\"settings_language_selection_toggle\").childSelector(className(\"android.widget.Switch\"))")
正如你所看到的,一些模板可以省略,例如: new UiSelector().resourceId(...)
可以简化为 resourceId(...)
. 还有一点:一旦你找到了根元素(具有给定资源Id的LinearLayout),你可以使用 .childSelector()
方法,嵌套并不重要。