Reputation: 1831
I am having a hard time learning how to use the UiSelector class found in android.support.test.uiautomator. I have tried several times to chain the methods but can't find a way. The last thing I tried looked like this:
self.driver.find_element_by_android_uiautomator('
new UiSelector().fromParent("
new UiSelector().resourceId(\"com.android.app:id/content_container\")").index(1)')
How can I get a child object from a parent object using UiSelector? Can someone help me to understand this? Thank You in advance.
Upvotes: 1
Views: 3648
Reputation: 982
If you're using Appium I'm not sure how it goes. But on basic UIAutomator you don't have to chain new UiSelector(), you build one instance of UiSelector with chained properties. For instance
UiSelector selector = new UiSelector().resourceId(<resource_id>).className(<className>).clickable(true);
UiObject object = device.findObject(selector);
I'm assuming you have a UiDevice.device.
You can also use BySelector and obtain UiObject2:
BySelector selector = By.clazz(<class_name>).res(<resource_id>);
List<UiObject2> objects = device.findObjects(selector);
Upvotes: 1