Search code examples
appium

How can I access an element in GridView with more rRelativeLayouts


I am using appium 1.6.5 and trying to access an Element in a GridView with more RelativeLayouts (0-7)

Screenshot from uiAutomatorViewer I have already tried all the possible commands

// aDriver.findElementsByClassName("android.widget.RelativeLayout").get(4)
/*
List<MobileElement> icons = aDriver.findElementsByClassName("\"android.widget.RelativeLayout\"");

icons.get(4).click();
*/

    aDriver.findElementByAndroidUIAutomator("new UiSelector().className(\"android.widget.RelativeLayout\").instance(4)").click();
// INFO: Also using index instead of instance did not hel UiSelector().className(\"android.widget.RelativeLayout\").index(4)").click()

but no success and I get the following Errors

[debug] [AndroidBootstrap] Sending command to android: {"cmd":"action","action":"find","params":{"strategy":"-android uiautomator","selector":"new UiSelector().className(\"android.widget.RelativeLayo
ut\").instance(4)","context":"","multiple":false}}
[HTTP] <-- POST /wd/hub/session/320ad077-e2fb-4304-9017-bb7aaba0ae1b/element - - ms - -
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"-android uiautomator","selector":"new UiSelector().className(\"android.widget.Re
lativeLayout\").instance(4)","context":"","multiple":false}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: find
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding 'new UiSelector().className("android.widget.RelativeLayout").instance(4)' using 'ANDROID_UIAUTOMATOR' with the contextId: '' multiple: false
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Parsing selector: new UiSelector().className("android.widget.RelativeLayout").instance(4)
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] UiSelector coerce type: java.lang.Class<T> arg: "android.widget.RelativeLayout"
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] UiSelector coerce type: class java.lang.String arg: "android.widget.RelativeLayout"
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] UiSelector coerce type: int arg: 4

Would appreciate any support Thanks


Solution

  • Try this : List icons = aDriver.findElementsByClassName("android.widget.RelativeLayo‌​ut"); icons .get(4).click();