简体   繁体   中英

Trying to Get child node(Switch ) from Parent(LinearLayout) via AndroidFindby(resourceid), Appium

(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)

///////////// You can have a look at the hierarchical representation of the elements below

Hierarchy Image View:

***I have tried to reach the switch button by writing the below code on appium Android for java, but it did not work

@AndroidFindBy(xpath ="new UiSelector().resourceId(\"com.idscan.mjcs.sample:id/settings_language_selection_toggle\").instance(1).getChildById(new UiSelector().className(\"android.widget.Switch\")

You using UiSelector syntax in XPath strategy. That is why it isn't working. Try this one:

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

As you can see here, some boilerplate can be omitted, eg new UiSelector().resourceId(...) can be simplified to resourceId(...) . One more thing: once you found the root element (LinearLayout with the given resourceId), you can find any child element in the hierarchy using .childSelector() method, nesting doesn't matter.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM