试图通过AndroidFindby(resourceid)从Parent(LinearLayout)获取子节点(Switch),Appium

问题描述 投票:0回答:1
(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 appium parent-child resource-id
1个回答
0
投票

你在XPath策略中使用了UiSelector语法。这就是为什么它不能工作的原因。试试这个。

@AndroidFindBy(uiAutomator = "resourceId(\"settings_language_selection_toggle\").childSelector(className(\"android.widget.Switch\"))")

正如你所看到的,一些模板可以省略,例如: new UiSelector().resourceId(...) 可以简化为 resourceId(...). 还有一点:一旦你找到了根元素(具有给定资源Id的LinearLayout),你可以使用 .childSelector() 方法,嵌套并不重要。

© www.soinside.com 2019 - 2024. All rights reserved.