5

I have a UITableView which contains about 50 elements. At any point only 6 of them are visible on screen. I want to select a cell which is not added to table view or say I need to select 25th item from the data list.

Now I am using this method for clicking a cell in tableview

wait.until(ExpectedConditions.visibilityOf(driver.findElementByAccessibilityId(element))).click();

But its not working as the 25th element is not added to the view yet. Please note that I am adding the accessibility identifier for the table view cell dynamically within the code.

How can I make this work?

***** Added more details******

I have the table view cell displaying two text views. Currency Short Name and Currency Long Name.

Consider the example

GBP

Great Britain Pounds

Now the accessibility Identifier for that tableview cell is set as GBP. Now I tried

driver.scrollTo("GBP") and driver.scrollTo("Great Britain Pounds")

Both didnt work. I am getting an error message

A element could not be located on the page using the Search parameter

Thanks.

Zach
  • 9,989
  • 19
  • 70
  • 107
  • 1
    Do you know the text of the element? because driver.scrollTo("Text") works like a charm in iOS. – Tabish Javed May 26 '16 at 05:22
  • Have you given X-Path a try? Index in x-path should help you access the element while scrolling. – Naman May 26 '16 at 05:50
  • I think you should display cell before select it. May be you should scroll to the destination cell (with a table view method), and after that try to select it. To find cell index you can determine its model in the models array. It needed because TableView reuses the cells, and you change AccessibilityId in runtime for any tableView's cells – Andrew Romanov May 31 '16 at 05:03
  • Also you can scroll table view to some offset, if you know cell's height, before try to find it. – Andrew Romanov May 31 '16 at 05:07

1 Answers1

1
    String ReqN = "Your required string"; 
    boolean flag = true;
    while (flag) {
        for (i=1;i<=6;i++) {
            String GetN = driver.findElement(By.xpath("//android.widget.HorizontalScrollView/android.widget.LinearLayout[" + i + "]")).getText();
            if (GetN.equals(ReqN)) {
                flag = false;
                System.out.println("Your result found");
            }
        }
        if (flag) {
            driver.swipe(145, 765, 145, 180, 3000);
        }
    }

String ReqN :: Your predefined string

String GetN :: Text get for each element [1 to 6 which we get by for loop ]

So it get text & match for first six elements if your predefined text not found then it swipe from given axes [ which is 6th element to 1st element ] ..so you will get new six element & loop will be executed again.

Ref. Image Elements & X,Y points