How to click on a particular element from list of elements

Hi There!

WebElement profile = driver.findElements(By.xpath("//android.view.ViewGroup"));
i got 9 elements with same class name from find elements now i want to click on 6th and after that 7th element is there any way to do it with appium java please help me.

Thanks in advance

You are using wrong syntax because if you use the findElements() should return the List of web elements.

Code will be like in this way:

List profile = driver.findElements(By.xpath("//android.view.ViewGroup"));

Thanks for the reply, actually i used below code, my question is about to click on particular element which has lot of elements with same id
List profile = driver.findElements(By.xpath("//android.view.ViewGroup"));

@Prashanth @Gnaneshwar-ggk just little more correction:

        List<AndroidElement> profile = driver.findElements(MobileBy.xpath("//android.view.ViewGroup"));
        if (!profile.isEmpty()) {
            System.out.println(profile.get(8).getText()); // print text in 9th element

Thank You @Aleksei

it prints the size not text, all the elements has only class name no text at all so how can i click on 6th element.
for last element i used below code and it works fine.

List webElements = driver.findElements(By.xpath("//android.view.ViewGroup"));
WebElement lastElement = Iterables.getLast(webElements, driver.findElement(By.xpath("//android.view.ViewGroup")));;

@Prashanth to click on 6th you need:

((AndroidElement) webElements.get(5)).click();